Windows消息:如何自定义窗口消息与线程消息
1个回答
展开全部
自定义消息
一、自定义窗口消息
#define WM_MY_MSG WM_USER + 0x100
afx_msg LRESULT OnMyMsg(WPARAM, LPARAM);
LRESULT CTestDlg::OnMyMsg(WPARAM wParam, LPARAM lParam)
{...}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
...
ON_MESSAGE(WM_MY_MSG, &CTestDlg::OnMyMsg)
END_MESSAGE_MAP()
二、自定义线程消息
#define WM_MY_THRD_MSG WM_USER + 100
afx_msg void OnMyThrdMsg(WPARAM, LPARAM);
void CTestApp::OnMyThrdMsg(WPARAM wParam, LPARAM lParam)
{...}
BEGIN_MESSAGE_MAP(CTestApp, CWinAppEx)
...
ON_THREAD_MESSAGE(WM_MY_THRD_MSG, &CTestApp::OnMyThrdMsg)
END_MESSAGE_MAP()
那怎样在当前线程中触发消息呢?有以下两种方法:
::PostMessage(NULL, WM_MY_THRD_MSG, 0, 0);
::PostThreadMessage(::GetCurrentThreadId(), WM_MY_THRD_MSG, 0, 0);
一、自定义窗口消息
#define WM_MY_MSG WM_USER + 0x100
afx_msg LRESULT OnMyMsg(WPARAM, LPARAM);
LRESULT CTestDlg::OnMyMsg(WPARAM wParam, LPARAM lParam)
{...}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
...
ON_MESSAGE(WM_MY_MSG, &CTestDlg::OnMyMsg)
END_MESSAGE_MAP()
二、自定义线程消息
#define WM_MY_THRD_MSG WM_USER + 100
afx_msg void OnMyThrdMsg(WPARAM, LPARAM);
void CTestApp::OnMyThrdMsg(WPARAM wParam, LPARAM lParam)
{...}
BEGIN_MESSAGE_MAP(CTestApp, CWinAppEx)
...
ON_THREAD_MESSAGE(WM_MY_THRD_MSG, &CTestApp::OnMyThrdMsg)
END_MESSAGE_MAP()
那怎样在当前线程中触发消息呢?有以下两种方法:
::PostMessage(NULL, WM_MY_THRD_MSG, 0, 0);
::PostThreadMessage(::GetCurrentThreadId(), WM_MY_THRD_MSG, 0, 0);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询