Re: pointer to a mfc form

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jerry Coffin (jcoffin_at_taeus.us)
Date: 04/30/04


Date: Fri, 30 Apr 2004 11:41:47 -0600

In article <#aIgPtaLEHA.3904@TK2MSFTNGP09.phx.gbl>,
rogerh40NoSpam@mindspring.com says...

[ ... ]
 
> I am writing a program using mfc because I want a windows interface. I
> am using a generic C++ class, but I want to add data to a listbox in a
> edit box on a mfc formview class from my generic class. I know I need
> to create a pointer to the form, but I can't seem to figure out how to
> do this without getting tons of compiler errors. I know this should be
> very simple so I was wondering if someone who knows how to do this could
> supply me with some sample code that I could look over on how to do
> this? Just something simple, it does not have to be very fancy. If I
> can't figure out how to do it this time, I guess I will have to go back
> to borland builder C++; I have no problem in builder doing this, but I
> wanted to do it in visual c++.

MFC is really intended to work somewhat differently than you seem to
be thinking (really, almost the opposite of how it sounds like you're
thinking).

At least if I understand you correctly, your current "generic class"
is basically a container for some data, and you want to display that
data in a list box in a form (or perhaps in both an edit box and a
list box in the form?)

In any case, to do that you do NOT want to pass a pointer to the view
class(es) to the generic class. Rather, you want to make the generic
class part of the Document class. The View class contains an OnDraw
member function that's responsible for updating the actual display of
the data.

One of the first things the default OnDraw does (in fact, nearly ALL
the default OnDraw does) is retrieve a pointer to the Document object
with which it's associated.

Then, you add code to the OnDraw to display that data in whatever way
is appropriate. In the case of a FormView, you'll normally want to
associate member variables with your control(s), and use them to
update the display.

I've created a small demonstration of this and posted it at:
http://www.coders-central.org/disp.zip
Most of it is a stock AppWizard FormView-based application. The
parts I've added are:

1) put an edit control in the dialog and associated it with a CString
member variable.
2) added a string to the document.
3) added a handler for the content of the edit control having
changed. This handler makes no attempt at being very smart --
anytime the data changes, it just copies the entire contents of the
edit control into the Document's string.
4) added an OnDraw that's equally stupid -- it just copies the whole
string into the current view's control.

Now, if you compile and run this, it'll create a window with an edit
control in its top half. If you go to the Window menu, you can
create another window.

You can now type into one window, and your modifications will
immediately show up in the other -- and the same will work with an
arbitrary number of windows too. To support this, the generic object
holding the data in the view knows precisely NOTHING about any of the
views, and never has to retrieve a pointer to any view.

-- 
    Later,
    Jerry.
The universe is a figment of its own imagination.


Relevant Pages

  • Re: [9fans] Using the Acme Editor
    ... file in a window above the one you are editing. ... middle clicking the Edit command ... Lisp is a very editor friendly language. ...
    (comp.os.plan9)
  • Re: Aufbau von mit NAME erzeugter Objekte
    ... Die WINDOW Klausel bei ... Um auf die EDIT bezogenen Ereignisse zu reagieren, ... EDIT WINDOW PreviewWin NAME oTest ... Browse ausgeführt wird.. ...
    (microsoft.public.de.fox)
  • Re: Windows & Dialog Stencil
    ... the Open at the bottom of the Edit menu is to ... stencil, you need to open the stencil and then right click the ... Then I can proceed to the "Show ShapeSheet" window and edit each ... User.Active is a boolean cell that is ...
    (microsoft.public.visio.general)
  • Re: Editing ListView Fields
    ... ListView. ... EDIT window over the field. ... controls' which is what the EDIT control is classified as. ...
    (microsoft.public.win32.programmer.ui)
  • Re: Browse with Partition REdit Problem
    ... NOMENU PARTITION 40 LPARTITION REDIT; ... TITLE "Dealer rolodex file sorted by zip" WINDOW winResults ... of view below the screen border. ... moves down one and the select edit on the right has focus to new record ...
    (microsoft.public.fox.programmer.exchange)