I have already introduced how to directly click the close button to close the application. But what functions do I need to delete a window object? For example, if you have created 30 windows and want to close and delete 12th windows, you need to use the destroywindow function. After the destroywindow function is called, the operating system will perform a series of Delete actions, first send the wm_destroy message, and then send the wm_ncdestroy message. If this window has a subwindow or another window owner, you need to send a delete message to all subwindows. The destroywindow function declaration is as follows: winuserapiboolwinapidestroywindow (_ in hwnd );
HwndIs the window handle to be deleted. Example of calling this function: #001 // #002 // function: wndproc (hwnd, uint, wparam, lparam) #003 // #004 // objective: process messages in the main window. #005 // #006 // Cai junsheng 2007/07/12 QQ: 9073204 #007 // #008 lresult callback wndproc (hwnd, uint message, wparam, lparam) #009 {#010 int wmid, wmevent; #011 paintstruct pS; #012 HDC; #013 #014 switch (Message) #015 {#016 case wm_command: #017 wmid = loword (wparam); #018 wmevent = hiword (wparam); #019 // menu option command response: #020 switch (wmid) #021 {#022 case idm_about: #023 dialogbox (hinst, makeintresource (idd_aboutbox), hwnd, about); #024 break; #025 case idm_exit:
#026 destroywindow (hwnd );#027 break; #028 default: #029 return defwindowproc (hwnd, message, wparam, lparam); #030} #031 break; #032 case wm_paint: #033 HDC = beginpaint (hwnd, & PS); #034 // #035 endpaint (hwnd, & PS); #036 break; #037 case wm_destroy: #038 postquitmessage (0); #039 break; #040 default: #041 return defwindowproc (hwnd, message, wparam, lparam); #042} #043 return 0; #044} row 26th is the message that when the menu button exits, the destroywindow function is called, and then the message wm_destro is sent. Y to 37th rows for processing.