# Include <windows. h> # include <stdio. h> lresult callback winuoowproc (// callback function declaration hwnd, uint umsg, wparam, lparam); int winapi winmain (hinstance, // winmain main function hinstance hprevinstance, lpstr lpcmdline, int ncmdshow) {wndclass wndcls; // create a window class wndcls. cbclsextra = 0; wndcls. cbwndextra = 0; wndcls. hbrbackground = (hbrush) getstockobject (black_brush); wndcls. hcursor = loadcursor (null, idc_cross); wndcl S. hicon = loadicon (null, idi_error); wndcls. hinstance = hinstance; wndcls. lpfnwndproc = winuoowproc; wndcls. lpszclassname = "first window"; wndcls. lpszmenuname = NULL; wndcls. style = cs_dblclks | cs_hredraw | cs_vredraw; registerclass (& wndcls); // registration window hwnd; // create window hwnd = createwindow ("first window", "window by dancer_dus7 ", ws_overlappedwindow, 300,200,600,400, null, null, hinstance, null); showwindow (hwnd, sw_shownormal );/ /Display window updatewindow (hwnd); // update window MSG; while (getmessage (& MSG, null/* hwnd )) // note that if the comments are changed to hwnd, the program will still run in Task Manager {translatemessage (& MSG); dispatchmessage (& MSG);} return 0 ;} lresult callback winuoowproc (// callback function hwnd, uint umsg, wparam, lparam) {Switch (umsg) // Message Processing {Case wm_char: Char szchar [20]; sprintf (szchar, "char is % d", wparam); MessageBox (hwnd, szchar, "key code:", 0); break; Case wm_lbuttondow N: MessageBox (hwnd, "Mouse clicked! "," Mouse ", mb_ OK); HDC = getdc (hwnd); textout (HDC, 0, 50," Hello world! ", Strlen (" Hello world! "); Releasedc (hwnd, HDC); break; Case wm_paint: HDC; paintstruct pS; HDC = beginpaint (hwnd, & PS); textout (HDC, 0, 0, "First window! ", Strlen (" first window! "); Endpaint (hwnd, & PS); break; Case wm_destroy: postquitmessage (0); break; default: Return defwindowproc (hwnd, umsg, wparam, lparam );} return 0 ;}
In the description in msdn, avoid the use of while (getmessage (lpmsg, hwnd, 0, 0) to avoid the result of-1. The window has been destroyed but is still running.
Note that the function return value can be nonzero, zero, or-1. Thus, you shoshould avoid code like this:
(Getmessage (lpmsg, hwnd, 0, 0 ))...
The possibility of a-1 return value means that such code can lead to fatal application errors.
While (getmessage (lpmsg, null, 0, 0) is correct.
However, I still don't think it is clear, that is, when the second parameter of getmessage is hwnd, the window is destroyed and the program is still running in the task management window, what does msdn not seem to understand? Hope you can answer your questions.