void CMainFrame::DoPopupMenu() { // Creates the popup menu for the "View Menu" toolbar button // Position the popup menu CToolBar& TB = GetToolBar(); CRect rc = TB.GetItemRect(TB.CommandToIndex(IDM_VIEWMENU)); TB.MapWindowPoints(NULL, (LPPOINT)&rc, 2); TPMPARAMS tpm; tpm.cbSize = sizeof(TPMPARAMS); tpm.rcExclude = rc; // Load the popup menu CMenu TopMenu(IDM_VIEWMENU); CMenu PopupMenu = TopMenu.GetSubMenu(0); // Put a radio check in the currently checked item MENUITEMINFO mii; ZeroMemory(&mii, sizeof(MENUITEMINFO)); for (int i = 3 ; i < 7 ; i++) { ZeroMemory(&mii, GetSizeofMenuItemInfo()); mii.cbSize = GetSizeofMenuItemInfo(); mii.fMask = MIIM_STATE | MIIM_ID; CMenu SubMenu = GetFrameMenu().GetSubMenu(1); SubMenu.GetMenuItemInfo(i, mii, TRUE); if (mii.fState & MFS_CHECKED) TopMenu.CheckMenuRadioItem(IDM_VIEW_SMALLICON, IDM_VIEW_REPORT, mii.wID, 0); } // Start the popup menu PopupMenu.TrackPopupMenuEx(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL, rc.left, rc.bottom, *this, &tpm); }
//**************************************************************************************** void CBCGPToolbarSystemMenuButton::OnDblClick (CWnd* pWnd) { if (CBCGPToolBar::IsCustomizeMode ()) { return; } ASSERT (pWnd != NULL); ////////////////////////////////////////////// // Make sure to close the popup menu and // find the MDI frame correctly. //-------------------------------------------- OnCancelMode (); CFrameWnd* pParentFrame = BCGPGetParentFrame (pWnd); if(pParentFrame != NULL && pParentFrame->IsKindOf (RUNTIME_CLASS (CMiniDockFrameWnd))) { pParentFrame = (CFrameWnd*) pParentFrame->GetParent (); } CMDIFrameWnd* pMDIFrame = DYNAMIC_DOWNCAST (CMDIFrameWnd, pParentFrame); if (pMDIFrame != NULL) { CMDIChildWnd* pChild = pMDIFrame->MDIGetActive (); ASSERT_VALID (pChild); BOOL bCloseIsDisabled = FALSE; CMenu* pSysMenu = pChild->GetSystemMenu (FALSE); if (pSysMenu != NULL) { MENUITEMINFO menuInfo; ZeroMemory(&menuInfo,sizeof(MENUITEMINFO)); menuInfo.cbSize = sizeof(MENUITEMINFO); menuInfo.fMask = MIIM_STATE; pSysMenu->GetMenuItemInfo (SC_CLOSE, &menuInfo); bCloseIsDisabled = ((menuInfo.fState & MFS_GRAYED) || (menuInfo.fState & MFS_DISABLED)); } if (!bCloseIsDisabled) { pChild->SendMessage (WM_SYSCOMMAND, SC_CLOSE); } } //-------------------------------------------- ////////////////////////////////////////////// }
STDMETHODIMP ExplorerBar::QueryContextMenu(HMENU hShellContextMenu, UINT iContextMenuFirstItem, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { DEBUG_UNUSED( idCmdLast ); DEBUG_UNUSED( uFlags ); CMenu menubar; menubar.LoadMenu(IDR_CONTEXT_MENU); CMenu * menu = menubar.GetSubMenu(0); CMenu shellmenu; shellmenu.Attach(hShellContextMenu); UINT iShellItem = iContextMenuFirstItem; //! remove plus one UINT idShellCmd = idCmdFirst; int n = menu->GetMenuItemCount(); for (int i=0; i<n; ++i) { MENUITEMINFO mii; TCHAR sz[128] = {0}; ZeroMemory(&mii, sizeof(mii)); mii.fMask = MIIM_TYPE | MIIM_ID; mii.fType = MFT_STRING; mii.cbSize = sizeof(mii); mii.cch = LENGTHOF(sz); mii.dwTypeData = sz; menu->GetMenuItemInfo(i, &mii, TRUE); mii.wID = idShellCmd++; shellmenu.InsertMenuItem(iShellItem++, &mii, TRUE); } shellmenu.Detach(); return n; }