我想在MFC中有一個消息處理程序,它接受我在消息映射中定義的任何參數。mfc - 帶自定義參數的sendmessage/postmessage
例如,
static UINT UWM_STATUS_MSG = RegisterWindowMessage("Status message");
static UINT UWM_GOT_RESULT= RegisterWindowMessage("Result has been obtained");
//{{AFX_MSG(MyClass)
afx_msg void OnCustomStringMessage(LPCTSTR);
afx_msg void OnStatusMessage();
//}}AFX_MSG
BEGIN_MESSAGE_MAP(MyClass, CDialog)
//{{AFX_MSG_MAP(MyClass)
ON_REGISTERED_MESSAGE(UWM_STATUS_MSG, OnStatusMessage)
ON_REGISTERED_MESSAGE(UWM_GOT_RESULT, OnCustomStringMessage)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void MyClass::OnCustomStringMessage(LPCTSTR result)
{
m_result.SetWindowText(result);
}
void MyClass::OnStatusMessage()
{
// Do something
}
DWORD WINAPI MyClass::thread(LPVOID lParam)
{
char result[256] = { 0 };
SendMessage(UWM_STATUS_MSG);
// Do some stuff and store the result
PostMessage(UWM_GOT_RESULT, result);
}
這種事可能嗎?
所以沒有辦法繞過'WPARAM'和'LPARAM'變量作爲參數?我只是認爲所有這些鑄造和額外的變數都是不必要的。我想知道是否有一些更適合我的任務的其他消息處理方法。因此,這個問題。謝謝你的回答! – 2013-03-25 10:10:23
另外,關於「結果」,是的。但這只是我想要的一些小示範。我會照顧這一切的。謝謝:) – 2013-03-25 10:11:04
不,你不能將其他類型的參數傳遞給這樣的成員函數。如果您擔心額外的變量,您也可以編寫「m_result.SetWindowText((LPCTSTR)p1)」。 – 2013-03-25 12:37:42