MFC在消息中发送对象

时间:2013-05-13 19:35:32

标签: c++ mfc

我可以用对象发送消息吗? 类似的东西:

myClass *myObj = new myClass();
pDlg->SendMessage(MyEvent, NULL, (LPARAM)&myObj); // Sends without any errors
...
afx_msg LRESULT MyApp::GetEvent(WPARAM wParam, LPARAM lParam)
{
    myClass *zxc = new myClass();
    zxc = lParam; // Something like this... but doesn't work
}

1 个答案:

答案 0 :(得分:2)

只需在适当的位置转换指针:

<强>发件人:

pDlg->SendMessage(MyEvent, NULL, reinterpret_cast<LPARAM>(&myObj));

<强>接收器:

afx_msg LRESULT MyApp::GetEvent(WPARAM wParam, LPARAM lParam)
{
    myClass * zxc = reinterpret_cast<myClass*>(lParam);
    // ...
}