OnCmdMsg() VS PostMessage()

In the place you plan to post message:

a. If you are sure the WM_Command can be handled by view/document, you can directly call View::OnCmdMsg() or Doc::OnCmdMsg() to post the message;

b. If you don't know where in the command routing way will handle the command, you have to use ::PostMessage or CWnd::PostMessage() which is inside calling ::PostMessage(). See below source code:

(c:"Program Files"Microsoft Visual Studio 9.0"VC"atlmfc"include"afxwin2.inl)

_AFXWIN_INLINE BOOL CWnd::PostMessage(UINT message, WPARAM wParam, LPARAM lParam)

{ ASSERT(::IsWindow(m_hWnd)); return ::PostMessage(m_hWnd, message, wParam, lParam); }

PostMessage 和SendMessage的区别主要在于是否等待其他程序消息处理。PostMessage只是把消息放入队列,不管其他程序是否处理都返回,然后继续执 行;而SendMessage必须等待其他程序处理消息后才返回,继续执行。这两个函数的返回值也不同,PostMessage的返回值表示 PostMessage函数执行是否正确,而SendMessage的返回值表示其他程序处理消息后的返回值。

你可能感兴趣的:(message)