Define your
FSM_MESSAGE
in
pch.h
or
stdafx.h
depending on VC++ version. Make sure
WM_APP+200
is not already used in your project.
#define FSM_MESSAGE WM_APP+200
Declare your handler function in dialog header
afx_msg LRESULT OnFsmMessage(WPARAM wparam, LPARAM lparam);
Link your function to the
FSM_MESSAGE
in between
BEGIN_MESSAGE_MAP
and
END_MESSAGE_MAP
in dialog cpp.
ON_MESSAGE(FSM_MESSAGE, &CSendMsgToParentExampleDlg::OnFsmMessage)
Implement your function this way.
LRESULT CSendMsgToParentExampleDlg::OnFsmMessage(WPARAM wparam, LPARAM lparam)
{
CString* pStr = reinterpret_cast<CString*>(wparam);
switch (lparam)
{
case 268:
m_edtText.SetWindowTextW(*pStr);
}
delete pStr;
return 0;
}
This is how to send msg to your parent from child dialog.
void ChildDialog::OnBnClickedBtnSendMsgToParent()
{
CString msg;
m_edtMsg.GetWindowTextW(msg);
CString* pStr = new CString(msg);
GetParent()->SendMessage(FSM_MESSAGE, (WPARAM)pStr, 268);
}
Getting confused? Take a look at sample code on
Example of sending message to parent dialog in MFC[
^]. Download it and play with it.