Starts a thread, creates a modelness dialog box with wtl, and then creates a message loop.
unsigned WINAPI MainDlg::ShowTipThread(LPVOID lpParameter){MainDlg* pThis = (MainDlg*) lpParameter;CMessageLoop theLoop;TipDlg theTipDlg;theTipDlg.Create(pThis->m_hWnd);theTipDlg.StartWorking();theLoop.Run();return 0;}
The dialog box can work, but it needs to communicate with the main interface thread,
Therefore, it is natural to use postthreadmessage.
void MainDlg::OnAction(){::PostThreadMessage(m_uThreadTip, WM_MY_MSG, 0, 0);}At this time, we find that thetipdlg cannot receive the custom message at all. However, if: postmessage (m_uthreadtip, wm_quit,), The subwindow can receive the message and destroy
I checked the msdn and found that I had the correct meaning. I mistakenly thought that the message sent to the thread using postmessage would be distributed to the window created by this thread.
1. Use postmessage to send messages to a thread. This thread must have a message queue created by the system for the thread. Calling peekmessage or getmessage will force the system to create a message queue for the thread.
2. The message can be received through a message loop. However, the window handle is not specified for the postmessage message, which will be filtered out.
The: dispatchmessage (& m_msg) is discarded, and wm_quit is special and will be processed before this.
3. A message queue is created by the system, and a message loop is created by a thread. A thread can create multiple windows,
Correct postthreadmessage usage