我正在尝试通过PostMessage从工作线程向主对话框线程发送消息。这一切都发生在我的对话框的一个类 - “CrMainDlg”中。 这里是“CrMainDlg.h”中处理函数原型的代码
afx_msg LRESULT OnThumbnailLoaded(WPARAM, LPARAM);
这是我在“#include”行之后的“CrMainDlg.cpp”中的新消息“
`UINT THUMBNAIL_WAS_LOADED = ::RegisterWindowMessage(L"THUMBNAIL_WAS_LOADED");`
这是我的MessageMap:
BEGIN_MESSAGE_MAP(CrMainDlg, CDialogEx)
//...
ON_MESSAGE(THUMBNAIL_WAS_LOADED, CrMainDlg::OnThumbnailLoaded)
//...
END_MESSAGE_MAP()
实现处理函数:
afx_msg LRESULT CrMainDlg::OnThumbnailLoaded(WPARAM, LPARAM)
{
AfxMessageBox(L"Func called!");
return 0;
}
然后在按钮点击上创建新线程:
void CrMainDlg::OnBnClickedButton1()
{
inputParam* iP = new inputParam;
iP->m_hWnd = ::FindWindow(NULL, L"rTestTask");
CWinThread* fonThread = AfxBeginThread(WorkerThreadProc, iP, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
}
至少是thread func:
UINT CrMainDlg::WorkerThreadProc(LPVOID Param)
{
if(Param == NULL)
{
AfxMessageBox(L"Params == NULL!");
return 0;
}
inputParam* p = (inputParam*)Param;
BOOL ch = ::PostMessage(p->m_hWnd, THUMBNAIL_WAS_LOADED, 0, 0); // ch == 1 =>no error
delete p;
return 0;
}
但是没有输入OnThumbnailLoaded - 我的句柄功能。请告诉我,我做错了什么?