Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ** Passing Variable Values to other Dialog Boxes **

** Passing Variable Values to other Dialog Boxes **

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Steve Lai
    wrote on last edited by
    #1

    Hi Everyone, How do I pass the values of a variable in one dialog box to another dialog box?? For example, let say I have a dialog box with an edit box and a button. So when I type something into the edit box and presses the button, the value of what I typed is stored in the variable for the edit box. Then how do I use that edit box variable in a DIFFERENT dialog box? Let say I want to display of whatever I typed in the edit box from the first dialog into a List box in the second dialog box, how do I do that? If anyone has any ideas, PLMK. Thanks in Advance! Steve

    T R 2 Replies Last reply
    0
    • S Steve Lai

      Hi Everyone, How do I pass the values of a variable in one dialog box to another dialog box?? For example, let say I have a dialog box with an edit box and a button. So when I type something into the edit box and presses the button, the value of what I typed is stored in the variable for the edit box. Then how do I use that edit box variable in a DIFFERENT dialog box? Let say I want to display of whatever I typed in the edit box from the first dialog into a List box in the second dialog box, how do I do that? If anyone has any ideas, PLMK. Thanks in Advance! Steve

      T Offline
      T Offline
      Tim Deveaux
      wrote on last edited by
      #2

      If the windows are active at the same time, and you can get the hWnd of one from the other (perhaps a parent/child realtionship) you might use GetDlgItem to get a handle to the control in the other window. Otherwise, you may have to set up a var somewhere that both dialogs can access.

      1 Reply Last reply
      0
      • S Steve Lai

        Hi Everyone, How do I pass the values of a variable in one dialog box to another dialog box?? For example, let say I have a dialog box with an edit box and a button. So when I type something into the edit box and presses the button, the value of what I typed is stored in the variable for the edit box. Then how do I use that edit box variable in a DIFFERENT dialog box? Let say I want to display of whatever I typed in the edit box from the first dialog into a List box in the second dialog box, how do I do that? If anyone has any ideas, PLMK. Thanks in Advance! Steve

        R Offline
        R Offline
        realJSOP
        wrote on last edited by
        #3

        Assumptions: 1) The other dialog box is instantiated when the button is pressed. 2) Both dialogs are contained in the same process (application). 3) You are familiar enough with Visual C and MFC to make this work. /////////////////////////////////////////////////////// Put this in a header file used by both dialog box class CPP files: const int UWM_MYMESSAGE = WM_APP + 1; /////////////////////////////////////////////////////// Put this code in the dialog box that has the button in it (substitute your own identifiers for the ones I used): CMyDialog1::OnButtonPressed() { CString sTemp; GetDlgItem(IDC_MYEDITCONTROL)->GetWindowText(sTemp); PostMessage(UWM_MYMESSAGE, (WPARAM)((LPCSTR)sTemp), 0); } //////////////////////////////////////////////////////// Put this line in the header file second dialog box that will be displaying the text: afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam); You have to put this just before the line that reads: DECLARE_MESSAGE_MAP() /////////////////////////////////////////////////////// Put his line in the CPP file for the second dialog box class: ON_MESSAGE(UWM_MYMESSAGE, OnMyMessage) Again, put the previous line just before this one: END_MESSAGE_MAP() /////////////////////////////////////////////////////// Lastly, put a function in the CPP file for the second dialog box class that handles the message: void CMyDialog2::OnMyMessage(int nMsgType, CString sMsg) { // m_MyText is an edit control declared as a CString // value m_MyText = (LPCTSTR)wParam; UpdateData(FALSE); } ======================================================= The code above allows you to exchange data between windows/dialogs without having to setup a global variables (global var'ables are bad, mmmokay?).

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups