1#include <Windows.h>2 3 //callback function for handling messages4 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);5 6 intWINAPI WinMain (hinstance hinstance, hinstance hpreinstance, PSTR szCmdLine,inticmdshow)7 {8 //set the name of the window9 StaticTCHAR szappname[ -] = TEXT ("Mywindow");Ten One //window class A wndclass wndclass; - //style -Wndclass.style = Cs_hredraw |Cs_vredraw; theWndclass.lpszclassname = Szappname;//Set name -Wndclass.lpszmenuname =NULL; -Wndclass.hbrbackground = (hbrush) getstockobject (White_brush);//Set Background -Wndclass.lpfnwndproc = WndProc;//Setting the Callback Function processing window +Wndclass.cbclsextra = Wndclass.cbwndextra =0;//Expand -Wndclass.hinstance = hinstance;//window Handle +Wndclass.hicon = LoadIcon (NULL, idi_application);//load Icon AWndclass.hcursor = LoadCursor (NULL, Idc_arrow);//Load Mouse Style at - //by name, register window - if(! RegisterClass (&wndclass)) - { -MessageBoxA (0,"Window registration failed","Tips",0); - return 0; in } - to //Create a window by name +HWND hwnd = CreateWindow (Szappname,//window name -TEXT ("window"),//Window Title theWs_overlappedwindow,//window Style *Cw_usedefault,//default display position x $Cw_usedefault,//default display position yPanax NotoginsengCw_usedefault,//Default Width -Cw_usedefault,//Default Height theNull//child window +Null//Sub-menu AHINSTANCE,//window Handle the NULL); + - ShowWindow (hwnd, sw_show); $UpdateWindow (HWND);//Display and update $MSG msg;//message - //message loop (GetMessage Create event TranslateMessage dispatchmessage response event) - while(GetMessage (&msg,null,0,0)) the { -TranslateMessage (&msg);Wuyi //Call callback function theDispatchMessage (&msg); - } Wu - returnMsg.wparam; About } $ - LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) - { - //Equipment Environment A HDC hdc; + paintstruct PS; the rect rect; - Switch(message) $ { the CaseWm_lbuttondown: theMessageBoxA (0,"press the left mouse button","Tips",0); the Break; the CaseWm_rbuttondown: -MessageBoxA (0,"press the left mouse button","Tips",0); in Break; the CaseWm_close: the if(MessageBoxA (0,"whether to close the window","Tips",1) ==1) About { the //Close window, send Wm_destroy message the DestroyWindow (HWND); the } + Else - { the return 0;Bayi } the Break; the CaseWm_destroy: -MessageBoxA (0,"was successfully closed","Tips",0); -Exit0); the Break; the default: the Break; the } - returnDefWindowProc (hwnd, message, wparam, lparam); the}
119.win32 window principle