** Passing Variable Values to other Dialog Boxes **
-
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
-
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
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.
-
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
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?).