MFC Question: DoDataExchange

Discussion in 'OT Technology' started by Joe_Cool, Apr 21, 2005.

  1. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,308
    Likes Received:
    563
    Is there such a thing as a quick & easy overview/explanation of this? I have a program due tomorrow where I'm required to use it with my dialogs.

    Or should I just take the 15 point markdown? :o
     
  2. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,308
    Likes Received:
    563
    I was absent the week they covered it in class.
     
  3. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    I usually don't mess with DoDataExchange. If you use the dialog editor, and use the wizard to link controls with data member variables, then DoDataExchnage is automatically generated for you.
     
  4. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    If you're wondering how it's used, DDX is most useful for dialogs that have lots of controls that need to be initialized and/or have data retrieved from them in one fell swoop.

    Say you have an edit box where a user is supposed to enter a number. You can use the add variable wizard to link that box to something like a DWORD member. Upon initialization of the dialog, you set the DWORD member to whatever default value is appropriate for that edit box. Initialize any other member variables that are linked to controls, then call UpdateData(FALSE). This will populate all the controls that are linked to member variables with whaterver is contained in those members.

    Now suppose the user edits whatever is in the controls, and clicks on an 'OK' button. In your OK button handler, you would call UpdateData(TRUE). This polls all the controls linked to members and validates and saves the control data to the associated member variables. You can use the add variable wizard to set the validation criteria (ranges of numbers for instance). UpdateData(TRUE) will return TRUE if all data is valid, FALSE otherwise.
     
  5. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,308
    Likes Received:
    563
    Ok. Are you familiar with this?

    Code:
    	CSingleDocTemplate* pDocTemplate;
    	pDocTemplate = new CSingleDocTemplate(
    		IDR_MAINFRAME,
    		RUNTIME_CLASS(COpenGL_MFCDoc),
    		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
    		RUNTIME_CLASS([b]COpenGL_MFCView[/b]));
    	AddDocTemplate(pDocTemplate);
    I need a reference or pointer to the object created when the bolded class is instantiated. This is the only place in my project that looks like an instantiation for that class, so how do I grab it? I need to set variables in the object, but can't figure out how to access it.
     
  6. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,308
    Likes Received:
    563

    Nice. Thanks for the tips. :)
     
  7. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
  8. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,308
    Likes Received:
    563

Share This Page