|
Can also send messages
If both window A and window B should be members of the main window class
Define the message name:
#define message name (e.g. UWM_SEND_AWND_TEXT) (WM_APP + 0x100)
// Main window class
Class The main window class (such as CMainFrame or CMyMainDlg, etc.)
{
CAwnd m_aWnd;
CBwnd m_bWnd;
proteted:
afx_msg LRESULT [Get message function name] (WPARAM, LPARAM);
}
// BEGIN_MESSAGE_MAP (CTestDlg, CDialog)
ON_MESSAGE (message name, get message function name)
// END_MESSAGE_MAP ()
// Get the message function entity
LRESULT main window class :: get message function name (WPARAM wParam, LPARAM lParam)
{
// Only the example here is a CString type object, if it is an arbitrary type object such as CRect, it will become
// CRect * pRect = (CRect) wParam; CRect m_rect = * pRect; ...
LPCTSTR * pText = (LPCTSTR *) wParam;
CString getText = * pText;
m_bWnd. Function to set value (getText); // Implement the string wParam from Form A to Form B
return 0;
}
Class CAwnd
{
}
CAwnd :: the name of the function to be sent
{
UpdateData (TRUE);
[Variable type to be transmitted] myObj; // such as CString myObj; CRect myObj, etc.
:: SendMessage (AfxGetApp ()-> GetMainWnd ()-> GetSafeHwnd (), message name, (WPARAM)&myObj, 0);
}
class CBwnd
{
}
CBwnd :: function to set value (CString getStr)
{
m_edtStr1 = getStr;
UpdateDate (FALSE);
} |
|