case WM_COMMAND:switch (LOWORD (wParam)){case IDM_WINDOW_TILE:SendMessage (hwndClient, WM_MDITILE, 0, 0) ;return 0 ; case IDM_WINDOW_CASCADE:SendMessage (hwndClient, WM_MDICASCADE, 0, 0) ;return 0 ; case IDM_WINDOW_ARRANGE:SendMessage (hwndClient, WM_MDIICONARRANGE, 0, 0) ;return 0; // //}break;2.当前子窗口的关闭
如果用户直接按下子窗口的关闭按钮,则WM_CLOSE消息直接发送到了子窗口消息处理函数。
例如:
框架窗口命令处理中:
case IDM_FILE_CLOSE: //获得当前激活窗口hwndChild = (HWND) SendMessage (hwndClient, WM_MDIGETACTIVE, 0, 0);//询问通过后,销毁窗口if (SendMessage (hwndChild, WM_QUERYENDSESSION, 0, 0)) SendMessage (hwndClient, WM_MDIDESTROY, (WPARAM) hwndChild, 0);return 0;子窗口的消息处理函数中:
LRESULT CALLBACK HelloWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ switch (message) {//// case WM_QUERYENDSESSION: case WM_CLOSE: if (IDOK != MessageBox (hwnd, TEXT ("OK to close window?"), TEXT ("Hello"), MB_ICONQUESTION | MB_OKCANCEL)) return 0 ; break ; // i.e., call DefMDIChildProc } return DefMDIChildProc (hwnd, message, wParam, lParam) ;}3.关闭所有子窗口
case IDM_WINDOW_CLOSEALL: //针对所有子窗口执行CloseEnumProcEnumChildWindows (hwndClient, CloseEnumProc, 0) ;return 0 ;枚举函数:
BOOL CALLBACK CloseEnumProc (HWND hwnd, LPARAM lParam){ if (GetWindow (hwnd, GW_OWNER)) // Check for icon title return TRUE ; SendMessage (GetParent (hwnd), WM_MDIRESTORE, (WPARAM) hwnd, 0) ; if (!SendMessage (hwnd, WM_QUERYENDSESSION, 0, 0)) return TRUE ; SendMessage (GetParent (hwnd), WM_MDIDESTROY, (WPARAM) hwnd, 0) ; return TRUE ;}六、菜单控制