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; }
void CQuickScripts::_PrepareViewMenu(int cItems) { if (m_wndButtonViews.m_menu == NULL) { CMenu menu; if (menu.LoadMenu(IDR_MENUVIEWS)) { // We only need to do this once... m_wndButtonViews.m_menu.Attach(menu.Detach()); } } if (m_wndButtonViews.m_menu) { UINT nID; if (_GetMenuItem("placeholder", &m_wndButtonViews.m_menu, &nID)) { CMenu *pMenuSub = m_wndButtonViews.m_menu.GetSubMenu(nID); // Clear the menu out first. UINT cItemsInMenu = pMenuSub->GetMenuItemCount(); while (cItemsInMenu > 0) { pMenuSub->RemoveMenu(0, MF_BYPOSITION); cItemsInMenu--; } // And rebuild for (int iIndex = 0; iIndex < cItems; iIndex++) { MENUITEMINFO mii = { 0 }; mii.cbSize = sizeof(mii); mii.fMask = MIIM_ID | MIIM_STRING; mii.wID = ID_GOTOVIEW1 + iIndex; mii.dwTypeData = "foo"; pMenuSub->InsertMenuItem(ID_GOTOVIEW1 + iIndex, &mii, FALSE); //menu.InsertMenuItem(ID_GOTOVIEW1 + iIndex, &mii, FALSE); } } } m_wndButtonViews.EnableWindow(cItems > 0); }
LRESULT CFloatingWindow::OnContextMenu(WORD wNotifyCode, WORD wID, HWND hWndCtl) { if (!IsWindowEnabled()) return 0; CMenu TrayMenu; TrayMenu.CreatePopupMenu(); if (!m_bIsUploading) { // Inserting menu items int i = 0; MyInsertMenu(TrayMenu, i++, IDM_UPLOADFILES, TR("Загрузить файлы") + CString(_T("..."))); MyInsertMenu(TrayMenu, i++, IDM_ADDFOLDERS, TR("Загрузить папку") + CString(_T("..."))); MyInsertMenu(TrayMenu, i++, 0, 0); bool IsClipboard = false; if (OpenClipboard()) { IsClipboard = IsClipboardFormatAvailable(CF_BITMAP) != 0; CloseClipboard(); } if (IsClipboard) { MyInsertMenu(TrayMenu, i++, IDM_PASTEFROMCLIPBOARD, TR("Вставить из буфера")); MyInsertMenu(TrayMenu, i++, 0, 0); } MyInsertMenu(TrayMenu, i++, IDM_IMPORTVIDEO, TR("Импорт видео")); MyInsertMenu(TrayMenu, i++, 0, 0); MyInsertMenu(TrayMenu, i++, IDM_SCREENSHOTDLG, TR("Скриншот") + CString(_T("..."))); MyInsertMenu(TrayMenu, i++, IDM_REGIONSCREENSHOT, TR("Снимок выделенной области")); MyInsertMenu(TrayMenu, i++, IDM_FULLSCREENSHOT, TR("Снимок всего экрана")); MyInsertMenu(TrayMenu, i++, IDM_WINDOWSCREENSHOT, TR("Снимок активного окна")); MyInsertMenu(TrayMenu, i++, IDM_WINDOWHANDLESCREENSHOT, TR("Снимок выбранного элемента")); MyInsertMenu(TrayMenu, i++, IDM_FREEFORMSCREENSHOT, TR("Снимок произвольной формы")); CMenu SubMenu; SubMenu.CreatePopupMenu(); SubMenu.InsertMenu( 0, MFT_STRING | MFT_RADIOCHECK | (Settings.TrayIconSettings.TrayScreenshotAction == TRAY_SCREENSHOT_OPENINEDITOR ? MFS_CHECKED : 0), IDM_SCREENTSHOTACTION_OPENINEDITOR, TR("Открыть в редакторе")); SubMenu.InsertMenu( 0, MFT_STRING | MFT_RADIOCHECK | (Settings.TrayIconSettings.TrayScreenshotAction == TRAY_SCREENSHOT_UPLOAD ? MFS_CHECKED : 0), IDM_SCREENTSHOTACTION_UPLOAD, TR("Загрузить на сервер")); SubMenu.InsertMenu( 1, MFT_STRING | MFT_RADIOCHECK | (Settings.TrayIconSettings.TrayScreenshotAction == TRAY_SCREENSHOT_CLIPBOARD ? MFS_CHECKED : 0), IDM_SCREENTSHOTACTION_TOCLIPBOARD, TR("Копировать в буфер обмена")); SubMenu.InsertMenu( 2, MFT_STRING | MFT_RADIOCHECK | (Settings.TrayIconSettings.TrayScreenshotAction == TRAY_SCREENSHOT_SHOWWIZARD ? MFS_CHECKED : 0), IDM_SCREENTSHOTACTION_SHOWWIZARD, TR("Открыть в окне мастера")); SubMenu.InsertMenu( 3, MFT_STRING | MFT_RADIOCHECK | (Settings.TrayIconSettings.TrayScreenshotAction == TRAY_SCREENSHOT_ADDTOWIZARD ? MFS_CHECKED : 0), IDM_SCREENTSHOTACTION_ADDTOWIZARD, TR("Добавить в мастер")); MENUITEMINFO mi; mi.cbSize = sizeof(mi); mi.fMask = MIIM_TYPE | MIIM_ID | MIIM_SUBMENU; mi.fType = MFT_STRING; mi.hSubMenu = SubMenu; mi.wID = 10000; mi.dwTypeData = TR("Действие со снимком"); TrayMenu.InsertMenuItem(i++, true, &mi); SubMenu.Detach(); MyInsertMenu(TrayMenu, i++, 0, 0); MyInsertMenu(TrayMenu, i++, IDM_SHORTENURL, TR("Сократить ссылку")); MyInsertMenu(TrayMenu, i++, 0, 0); MyInsertMenu(TrayMenu, i++, IDM_SHOWAPPWINDOW, TR("Показать окно программы")); MyInsertMenu(TrayMenu, i++, 0, 0); MyInsertMenu(TrayMenu, i++, IDM_SETTINGS, TR("Настройки") + CString(_T("..."))); MyInsertMenu(TrayMenu, i++, 0, 0); MyInsertMenu(TrayMenu, i++, IDM_EXIT, TR("Выход")); if (Settings.Hotkeys[Settings.TrayIconSettings.LeftDoubleClickCommand].commandId) { SetMenuDefaultItem(TrayMenu, Settings.Hotkeys[Settings.TrayIconSettings.LeftDoubleClickCommand].commandId, FALSE); } } else MyInsertMenu(TrayMenu, 0, IDM_STOPUPLOAD, TR("Прервать загрузку")); m_hTrayIconMenu = TrayMenu; CMenuHandle oPopup(m_hTrayIconMenu); PrepareMenu(oPopup); CPoint pos; GetCursorPos(&pos); SetForegroundWindow(m_hWnd); oPopup.TrackPopupMenu(TPM_LEFTALIGN, pos.x, pos.y, m_hWnd); // BUGFIX: See "PRB: Menus for Notification Icons Don't Work Correctly" PostMessage(WM_NULL); return 0; }