/winmain function
int Apientry WinMain (hinstance hinstance, hinstance hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
G_hinstance = hinstance;
if (! Register ("Main", WndProc))//Registration window class RegisterClassEx
{
MessageBox (NULL, "registration Failed", "Infor", MB_OK);
return 0;
}
HWND hwnd = Createmainwnd ("Main", "window"); Create Window CreateWindow
Display (HWND);
Message ();//messages Loop is responsible for handling messages from the OS in the main thread
return 0;
}
message loop (message pump)
void Message ()
{
MSG nmsg ={0};
while (GetMessage (&nmsg, NULL, 0, 0))
{
TranslateMessage (&NMSG);
DispatchMessage (&NMSG);
}
}
Windows message processing functions
LRESULT CALLBACK WindowProc (HWND hwnd, UINT nmsg, WPARAM WPARAM, LPARAM LPARAM)
{
Finally, messages you don't want to process are handed to the default message handler
Return DefWindowProc (hWnd, Nmsg, WParam, LParam); Default Windows Message handler function
}
Where the operating system sends the hardware messages to the message pump for each window's corresponding thread to process
//
If a window (WND) is created in a child thread, the message pump that processes the message needs to be in the child thread, and the message is not sent to the main thread's message loop
//
CreateThread (Null,0,threadproctrade,null,0,&threadid_trade);
DWORD WINAPI Threadproctrade (LPVOID lpparam)
{
G_hinstance = hinstance;
if (! Register ("Main", WndProc))//Registration window class RegisterClassEx
{
MessageBox (NULL, "registration Failed", "Infor", MB_OK);
return 0;
}
HWND hwnd = Createmainwnd ("Main", "window"); Create Window CreateWindow
Display (HWND);
Message (); Messages in the message loop sub-thread that are responsible for processing the UI created by this thread from the OS
return 0;
}
Windows message loops and window-to-thread relationships