Thread: passing value from one dlg to another

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    That snippet does not help since it won't even work.

    If you are subclassing a dialog in MFC then you can pass data from the dialog back to the caller in several ways.

    1. In the designer set a variable to be associated with the control. In code provide a means to get the value of this variable. When the dialog user presses OK call CDialog::UpdateData(TRUE). This will update the variables associated with controls to the value that is in the controls at the time the user pressed OK. Retrieve these variables from another class or object via pointers to the class or some other method.

    2. Set the variables manually by scanning the controls, retrieving their state (text, value, or other), storing that in class members, and retrieving later via pointers to the class or some other method.

    In both instances this requires that the CDialog derived object exists even after the user pressed OK and the dialog disappears or becomes hidden. If the CDialog object does not exist then the variables do not exist and you will have a serious problem if you try to access the object since it does not exist.

    Novacain also showed me this at one time and it has been a huge help. You can get a pointer to your main window by doing this:

    Code:
    CMainFrame *ptrFrame = (CMainFrame *)AfxGetMainWnd();
    You can use this pointer to access variables in your CFrameWnd derived class. Very handy.
    Last edited by VirtualAce; 11-24-2007 at 10:52 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Question on Passing Objects as Parameters
    By Mariano L Gappa in forum C++ Programming
    Replies: 12
    Last Post: 11-29-2006, 01:08 PM
  2. Replies: 7
    Last Post: 04-19-2006, 11:17 AM
  3. Passing by reference not always the best
    By franziss in forum C++ Programming
    Replies: 3
    Last Post: 10-26-2005, 07:08 PM
  4. passing by address vs passing by reference
    By lambs4 in forum C++ Programming
    Replies: 16
    Last Post: 01-09-2003, 01:25 AM