//..................................................................................................................... // // MDI : Implementation file. // // Copyright (C) 1990, 1999 LEAD Technologies, Inc. // All rights reserved. // //..................................................................................................................... #include "stdSDK.h" #include "resource.h" #include "Frame.h" #include "mdi.h" #include "paint.h" //#include "error.h" // If you are going to run under Win32s, you must enable the line below. // CreateMDIWindow does not exist in Win32s. #define USE_WM_MDICREATE L_BOOL MDI_DisplayContextMenu ( HWND hwnd, POINT pt, HMENU context ) { HMENU popup ; if ( context == NULL ) { return FALSE ; } popup = GetSubMenu ( context, 0 ) ; ClientToScreen ( hwnd, &pt ) ; MDI_ConformMenus ( GetMenu ( g_hMainFrame ), popup ) ; TrackPopupMenu ( popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, g_hMainFrame, NULL ) ; return TRUE ; } L_BOOL MDI_OnContextMenu ( HWND hwnd, HWND hwndCtl, L_INT xPos, L_INT yPos, HMENU context ) { POINT pt ; RECT rc ; UNREFERENCED_PARAMETER ( hwndCtl ) ; pt.x = xPos ; pt.y = yPos ; // Get the bounding rectangle of the client area of the child GetClientRect ( hwnd, &rc ) ; // Convert the mouse position to client coordinates ScreenToClient ( hwnd, &pt ) ; // If the mouse click was in the client area of this child window, // display the appropriate popup menu. if ( PtInRect ( &rc, pt ) ) { if ( MDI_DisplayContextMenu ( hwnd, pt, context ) ) { return TRUE ; } } // Otherwise, tell our caller that we don't handle it return FALSE ; } static L_VOID MDI_ConformMenus4(HMENU hMaster, HMENU hPopup) { MENUITEMINFO getpopupinfo ; MENUITEMINFO setpopupinfo ; MENUITEMINFO masterinfo ; L_INT i ; L_INT count ; count = GetMenuItemCount ( hPopup ) ; getpopupinfo.cbSize = sizeof ( MENUITEMINFO ) ; getpopupinfo.fMask = MIIM_SUBMENU | MIIM_ID ; setpopupinfo.cbSize = sizeof ( MENUITEMINFO ) ; setpopupinfo.fMask = MIIM_STATE ; masterinfo.cbSize = sizeof ( MENUITEMINFO ) ; masterinfo.fMask = MIIM_STATE ; for ( i = 0; i < count; i++ ) { // PROCESS EACH VERIFY ( GetMenuItemInfo ( hPopup, i, TRUE, &getpopupinfo ) ) ; if ( getpopupinfo.hSubMenu != NULL ) { // submenu MDI_ConformMenus4 ( hMaster, getpopupinfo.hSubMenu ) ; } // submenu else { // MENU ITEM GetMenuItemInfo ( hMaster, getpopupinfo.wID, FALSE, &masterinfo ) ; setpopupinfo.fState = masterinfo.fState ; SetMenuItemInfo ( hPopup, i, TRUE, &setpopupinfo ) ; } // MENU ITEM } // PROCESS EACH } static L_VOID MDI_ConformMenus3 ( HMENU hMaster, HMENU hPopup ) { L_UINT popupstate ; HMENU submenu ; L_INT count ; L_INT i ; count = GetMenuItemCount ( hPopup ) ; for ( i = 0; i < count; i ++ ) { // PROCESS EACH popupstate = GetMenuState ( hPopup, i, MF_BYPOSITION ) ; if ( ( popupstate & ~0xFF ) != 0 ) { // SUBMENU submenu = GetSubMenu ( hPopup, i ) ; MDI_ConformMenus3 ( hMaster, submenu ) ; } // SUBMENU else { // MENU ITEM L_UINT id ; L_UINT masterstate ; id = GetMenuItemID ( hPopup, i ) ; masterstate = GetMenuState ( hMaster, id, MF_BYCOMMAND ) ; EnableMenuItem ( hPopup, i, MF_BYPOSITION | ( masterstate & ( MF_ENABLED | MF_DISABLED | MF_GRAYED ) ) ) ; CheckMenuItem ( hPopup, i, MF_BYPOSITION | ( masterstate & ( MF_CHECKED | MF_UNCHECKED ) ) ) ; } // MENU ITEM } // PROCESS EACH } L_VOID MDI_ConformMenus ( HMENU hMaster, HMENU hPopup ) { OSVERSIONINFO info ; info.dwOSVersionInfoSize = sizeof ( info ) ; GetVersionEx ( &info ) ; if ( info.dwMajorVersion < 4 ) { MDI_ConformMenus3 ( hMaster, hPopup ) ; } else { MDI_ConformMenus4 ( hMaster, hPopup ) ; } } HWND MDI_Create ( HWND hwnd, L_UINT32 styles, L_INT classid, L_INT titleid, L_INT nX, L_INT nY, L_INT nWidth, L_INT nHeight ) { HINSTANCE hinst = GetWindowInstance ( hwnd ) ; HWND hwndChild ; TCHAR Class [ 80 ] ; TCHAR Title [ 80 ] ; #ifdef USE_WM_MDICREATE MDICREATESTRUCT mcs; #endif LoadString ( hinst, classid, Class, DIM ( Class ) ) ; LoadString ( hinst, titleid, Title, DIM ( Title ) ) ; #ifdef USE_WM_MDICREATE mcs.szClass = Class ; mcs.szTitle = Title ; mcs.hOwner = hinst ; mcs.x = nX ; mcs.y = nY ; mcs.cx = nWidth ; mcs.cy = nHeight ; mcs.style = styles ; mcs.lParam = 0 ; hwndChild = FORWARD_WM_MDICREATE ( hwnd, &mcs, SendMessage ) ; #else hwndChild = CreateMDIWindow ( Class, Title, MDIS_ALLCHILDSTYLES, nX, nY, nWidth, nHeight, hwnd, hinst, 0 ) ; #endif return hwndChild ; }