WM_QUIT 是比较特殊的消息,对于这个消息有一个专门的API:PostQuitMessage ,所以最好不要用SendMessage或是PostMessage,这一点MSDN上有,下面是MSDN原文: ResThe WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. It is retrieved only by the GetMessage or PeekMessage functions. Do not post the WM_QUIT message using the PostMessage function; use PostQuitMessage.
SendMessage是把消息传送到队列,然后等待消息处理完成,
WM_QUIT消息出来后,程序已经退出,就不会返回消息给等待线程,
从而造成等待线程一直等待,而不会退出!!!
不过没有试过,楼主要感兴趣可以试试
当GetMessage在消息队列中取到WM_QUIT时,GetMessage返回值为0,然后循环退出,主线程退出。另外建议使用PostQuitMessage()函数,而不是PostMessage(WM_QUIT);
ResThe WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. It is retrieved only by the GetMessage or PeekMessage functions. Do not post the WM_QUIT message using the PostMessage function; use PostQuitMessage.