Click here to Skip to main content
15,867,870 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wrote:

<pre>
GetParent()->SendMessage(FSM_MESSAGE, MAKEWPARAM((WPARAM)& string, 268), 0);





so I send to parent a string with the value 268...now...when I receive the message I have an error:

//case 268:
			
				//pstr = (CString*)wParam;
			

			//	m_Edit.SetWindowText(*pstr);
				
				//break;


What I have tried:

so I don't receive the right string..how can I do?
Posted
Updated 29-Sep-20 16:26pm
Comments
Richard Deeming 29-Sep-20 6:33am    
If you want someone to help you fix an error, you need to tell us what the error is.

Click the green "Improve question" link and update your question to include the full details of the error. Remember to indicate which line of code it relates to.
Shao Voon Wong 29-Sep-20 7:58am    
How do you define FSM_MESSAGE?
Shao Voon Wong 30-Sep-20 5:25am    
OP likes to ask questions on MFC. I advise him to learn MFC properly from a book.

I do not think you can create a valid pointer as the low order part of a WPARAM. You should change your code to:
C++
GetParent()->SendMessage(FSM_MESSAGE, 268, &string);

And adjust your message handler in the parent process.
 
Share this answer
 
v2
Comments
CPallini 29-Sep-20 8:00am    
And setting the high word of WPARAM to 268, doesn't help... :-)
5.
Richard MacCutchan 29-Sep-20 8:06am    
Thanks. And especially when LPARAM is free.
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.
C++
#define FSM_MESSAGE WM_APP+200

Declare your handler function in dialog header
C++
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.
C++
ON_MESSAGE(FSM_MESSAGE, &CSendMsgToParentExampleDlg::OnFsmMessage)

Implement your function this way.
C++
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.
C++
void ChildDialog::OnBnClickedBtnSendMsgToParent()
{
	CString msg;
	m_edtMsg.GetWindowTextW(msg);

	CString* pStr = new CString(msg); // make a copy else go out of scope

	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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900