WTL message mechanism
High song
First, SDI process
RUN global thread
1, Module.AddMessageloop (& TheLoop), save the CMessageLoop corresponds to a thread ID, Module is a global variable.
2, WNDMAIN construction, initialization variable
3, WNDMAIN Createex
WNDMAIN CREATE
Registration window class (the address of the window is startwindowproc)
Call the class CFrameWindowImplbase's Create
Save an instance of this to _Module.addcreateWnddata (& m_thunk.cd, this);
Win32 CreateWindow function
CREATEWINDOW will trigger the first WM_XXX message to call StartWindowProc
StartWindowProc is mainly to initialize a Thunk code and modify the window process to the beginning of THUNK. The Thunk code first puts the bit value in the stack in the stack, and then jumps to the WndProc function with the JMP.
4, call WNDMAIN.SHOWWINDOW (NCMDSHOW);
5, int nret = theloop.run ();
6, _Module.removeMessageloop ();
Thread end
Second, the message circulation
// theloop.run ();
Int run ()
{
Bool bdoidle = true;
INT NIDECOUNT = 0;
BOOL BRET;
For (;;)
{
// There is no message in the test queue
While (! :: PeekMessage (& M_MSG, NULL, 0, 0, PM_NOREMOVE) && bdoidle)
{
IF (! OnIdle (NidleCount ))
BDOIDLE = FALSE;
}
/ / Get the message and remove from the queue
Bret = :: getMessage (& M_MSG, NULL, 0, 0);
IF (BRET == -1)
{
Atltrace2 (Atltraceui, 0, _t (":: getMessage returned -1 (error) / n"));
Continue; // Error, Don't Process
}
// Bret is 0 to receive WM_QUIT
Else if (! BRET)
{
ATLTRACE2 (Atltraceui, 0, _T ("cMessageloop :: run - exiting / n"));
Break; // wm_quit, EXIT Message Loop
}
// PretranslateMessage traversed CMessageFilter If one is called and returns True
// If this function is defined in the window class and adding a FILTER, he will not be sent to the window.
// Note this function is a virtual function
IF (! PretranslateMessage)
{
:: TranslateMessage (& M_MSG);
:: DispatchMessage (& M_MSG);
}
IF (ISIDEMESSAGE))
{
BDOIDLE = True;
Nidlecount = 0;
}
}
Return (int) m_msg.wparam;
}
Third, ProcessMessage
ProcessMessage is a virtual function that is implemented by macro definition from the derived class.
WndProc call.
Reference article
http://www.rpi.edu/~pudeyo/articles/wndproc/