static void OnWindowCloseAll(void) { /* give user an opportunity for each child to save modified data or cancel the closeall */ if ( ChildQueryCloseAll() ) { /* ShowWindow is suggested in one of MS's examples to reduce flashing */ ShowWindow(hwndMDIClient, SW_HIDE); EnumChildWindows(hwndMDIClient, (BOOL (CALLBACK*)(HWND, LPARAM))EnumChildProcClose, 0); ShowWindow(hwndMDIClient, SW_SHOW); } }
LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { CLIENTCREATESTRUCT ccs; HWND hwndChild = 0; if ( IsWindow(hwndMDIClient) ) hwndChild = ChildGetActive(); switch ( uMsg ) { case WM_CREATE: /* following is regular MDI incantation */ ccs.hWindowMenu = GetSubMenu(GetMenu(hWnd), WINDOW_MENU_POS); ccs.idFirstChild = IDM_WINDOW_CHILDREN; hwndMDIClient = CreateWindow( "mdiclient", NULL, WS_CHILD | WS_CLIPCHILDREN, 0, 0, 0, 0, hWnd, 0, hinstThis, &ccs); if ( hwndMDIClient != 0 ) { ShowWindow(hwndMDIClient, SW_SHOW); /* subclass the hwndMDIClient window so we can change the cursor to a wait cursor when desired */ pfnOldMDIClientWndProc = (WNDPROC)SetWindowLong(hwndMDIClient, GWL_WNDPROC, (LONG)MDIClientWndProc); } return ( 0 ); case WM_INITMENUPOPUP: /* some popup menu is about to be displayed */ MenuStatus((int)LOWORD(lParam), (HMENU)wParam); return ( 0 ); case WM_COMMAND: /* if WM_COMMAND is not from a control (then it's from a menu item) */ if ( LOWORD(lParam) == 0 && MenuOnCommand(LOWORD(wParam)) ) return ( 0 ); break; case WM_QUERYENDSESSION: return ( ChildQueryCloseAll() ); case WM_CLOSE: if ( !ChildQueryCloseAll() ) return ( 0 ); break; case WM_DESTROY: WinHelp(hwndFrame, APPLICATION_HELPFILENAME, HELP_QUIT, 0); PostQuitMessage(0); return ( 0 ); case WM_QUERYNEWPALETTE: /* set the system palette to the active child's palette */ return ( OnQueryNewPalette(hwndChild) ); case WM_MDIACTIVATE: /* set the system palette to the newly active child's palette */ OnQueryNewPalette((HWND)wParam); return ( 0 ); case WM_PALETTECHANGED: /* forwarded to children so they can each realize their background palettes */ ForwardToChildren(hWnd, uMsg, wParam, lParam); return ( 0 ); case WM_SYSCOLORCHANGE: Ctl3dColorChange(); break; case WM_SYSCOMMAND: switch ( wParam & 0xfff0 ) { case SC_MAXIMIZE: case SC_RESTORE: /* since we effectively change our image origin when maximized or restored, we have to _force_ the window repaint to include the entire window -- else win '95 (at least) optimizes away some of the regions */ DefFrameProc(hWnd, hwndMDIClient, uMsg, wParam, lParam); if ( IsWindow(hwndChild) ) { InvalidateRect(hwndChild, NULL, FALSE); UpdateWindow(hwndChild); } return ( 0 ); default: break; } break; case WM_MOUSEMOVE: if ( nWaitCursor != 0 ) SetCursor(hWaitCursor); else SetCursor(hArrowCursor); break; default: break; } if ( !IsWindow(hwndMDIClient) ) return ( DefFrameProc(hWnd, 0, uMsg, wParam, lParam) ); return ( DefFrameProc(hWnd, hwndMDIClient, uMsg, wParam, lParam) ); }