void CDownloads_Groups::ShowHistoryContextMenu() { CMenu menu; menu.LoadMenu (IDM_GROUP); CMenu *pPopup = menu.GetSubMenu (2); ApplyLanguageToMenu_History (pPopup); pPopup->SetDefaultItem (ID_HISTORY_SETTINGS); if (_DldsMgr.m_histmgr.GetRecordCount () == 0) pPopup->EnableMenuItem (ID_HISTORY_CLEAR, MF_BYCOMMAND | MF_GRAYED); CPoint pt (m_rbX, m_rbY); ClientToScreen (&pt); m_odmenu.Attach (&menu, FALSE); fsSetImage images [] = { fsSetImage (ID_HISTORY_CLEAR, 2), fsSetImage (ID_HISTORY_SETTINGS, 3), }; m_odmenu.SetImages (images, sizeof (images) / sizeof (fsSetImage)); pPopup->TrackPopupMenu (TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_LEFTALIGN, pt.x, pt.y, this); m_odmenu.Detach (); menu.DestroyMenu (); }
LRESULT Cwinproc::OnTaskbarNotify(WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(wParam); switch (lParam) { case WM_MOUSEMOVE: { CString s, sRecvBPS, sRecvAVE; FormatBytes(RecvStats[0].Bps, sRecvBPS, true); FormatBytes(RecvStats[0].ave, sRecvAVE, true); s.Format("Current: %s Average: %s", sRecvBPS, sRecvAVE); m_SystemTray.cbSize = sizeof(NOTIFYICONDATA); m_SystemTray.hWnd = GetSafeHwnd(); m_SystemTray.uID = 1; m_SystemTray.uFlags = NIF_TIP; strcpy_s(m_SystemTray.szTip, s); Shell_NotifyIcon(NIM_MODIFY, &m_SystemTray); } break; case WM_LBUTTONDBLCLK: ShowPropertiesDlg(); break; case WM_RBUTTONUP: { CMenu menu; POINT pt; GetCursorPos(&pt); menu.LoadMenu(IDR_MENU1); menu.SetDefaultItem(0, TRUE); CMenu &pMenu = *menu.GetSubMenu(0); pMenu.SetDefaultItem(0, TRUE); // See Q135788 "PRB: Menus for Notification Icons Do Not Work Correctly" SetForegroundWindow(); int cmd = pMenu.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, pt.x, pt.y, this); PostMessage(WM_NULL, 0, 0); if (cmd == IDCLOSE) { // Save any settings if the user closes the tray icon while the dialog is open if (m_pPropertiesDlg != NULL) { SaveSettings(); m_pPropertiesDlg->SendMessage(WM_CLOSE); } theApp.m_wnd.PostMessage(WM_CLOSE); } else if (cmd == ID_PROPERTIES) ShowPropertiesDlg(); } break; } return 0; }
void CFolderListCtrl::OnRButtonUp(UINT nFlags, CPoint point ) { CListCtrl::OnRButtonUp(nFlags, point); CMenu m_ListPopup; m_ListPopup.LoadMenu( IDR_FOLDER_LIST ); CMenu * pListMenu = m_ListPopup.GetSubMenu( 0 )->GetSubMenu( 0 ); pListMenu->SetDefaultItem(ID_FILE_EDIT); ClientToScreen( &point ); pListMenu->TrackPopupMenu( TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd() ); }
/** * Todo * @param void * @return void */ void CTrayDialog::ShowMenu(CPoint pt) { if( m_mnuTrayMenu.m_hMenu ) { CMenu* menu = m_mnuTrayMenu.GetSubMenu(0); menu->SetDefaultItem(m_nDefaultMenuItem,TRUE); SetForegroundWindow(); menu->TrackPopupMenu(TPM_RIGHTBUTTON,pt.x,pt.y,this); PostMessage( WM_NULL, 0, 0 ); } }
void CEditTreeCtrl::DragDisplayContextMenu(CPoint & point) { CMenu menu; VERIFY(menu.CreatePopupMenu()); VERIFY(menu.AppendMenu(MF_STRING, ID_DRAG_COPY, _T("Copy Here"))); VERIFY(menu.AppendMenu(MF_STRING, ID_DRAG_MOVE, _T("Move Here"))); VERIFY(menu.AppendMenu(MF_SEPARATOR)); VERIFY(menu.AppendMenu(MF_STRING, ID_DRAG_CANCEL, _T("Cancel"))); bool bCtrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0; menu.SetDefaultItem(bCtrl ? ID_DRAG_COPY : ID_DRAG_MOVE); menu.TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this); }
// CMainFrame::OnChangeFileMenu() is a menu command handler for // CMainFrame class, which in turn is a CFrameWnd-derived class. // It modifies the File menu by inserting, removing and renaming // some menu items. Other operations include associating a context // help id and setting default menu item to the File menu. // CMainFrame is a CFrameWnd-derived class. void CMainFrame::OnChangeFileMenu() { // Get the menu from the application window. CMenu* mmenu = GetMenu(); // Look for "File" menu. int pos = FindMenuItem(mmenu, _T("&File")); if (pos == -1) return; // Remove "New" menu item from the File menu. CMenu* submenu = mmenu->GetSubMenu(pos); pos = FindMenuItem(submenu, _T("&New\tCtrl+N")); if (pos > -1) submenu->RemoveMenu(pos, MF_BYPOSITION); // Look for "Open" menu item from the File menu. Insert a new // menu item called "Close" right after the "Open" menu item. // ID_CLOSEFILE is the command id for the "Close" menu item. pos = FindMenuItem(submenu, _T("&Open...\tCtrl+O")); if (pos > -1) submenu->InsertMenu(pos + 1, MF_BYPOSITION, ID_CLOSEFILE, _T("&Close")); // Rename menu item "Exit" to "Exit Application". pos = FindMenuItem(submenu, _T("E&xit")); if (pos > -1) { UINT id = submenu->GetMenuItemID(pos); submenu->ModifyMenu(id, MF_BYCOMMAND, id, _T("E&xit Application")); } // Associate a context help ID with File menu, if one is not found. // ID_FILE_CONTEXT_HELPID is the context help ID for the File menu // that is defined in resource file. if (submenu->GetMenuContextHelpId() == 0) submenu->SetMenuContextHelpId(ID_FILE_CONTEXT_HELPID); // Set "Open" menu item as the default menu item for the File menu, // if one is not found. So, when a user double-clicks the File // menu, the system sends a command message to the menu's owner // window and closes the menu as if the File\Open command item had // been chosen. if (submenu->GetDefaultItem(GMDI_GOINTOPOPUPS, TRUE) == -1) { pos = FindMenuItem(submenu, _T("&Open...\tCtrl+O")); submenu->SetDefaultItem(pos, TRUE); } }
LRESULT CMainDlg::OnTrayNotification(WPARAM wParam, LPARAM lParam) { UINT uID = (UINT)wParam; UINT uMsg = (UINT)lParam; // Make sure its for us if(uID != IDR_TRAY_MENU) return 0; if(uMsg == WM_LBUTTONDBLCLK) { // Execute the default command ShowWindow(SW_RESTORE); return 1; } if(uMsg == WM_RBUTTONUP) { // Display the tray menu CMenu TrayMenu; CMenu* pSubMenu; if(!TrayMenu.LoadMenu(IDR_TRAY_MENU)) return 0; if(!(pSubMenu = TrayMenu.GetSubMenu(0))) return 0; // Set default menu item pSubMenu->SetDefaultItem(ID_SHOW); // Display and track the popup menu CPoint pos; GetCursorPos(&pos); SetForegroundWindow(); ::TrackPopupMenu(pSubMenu->m_hMenu, 0, pos.x, pos.y, 0, m_hWnd, NULL); // BUGFIX: See "PRB: Menus for Notification Icons Do Not Work Correctly" PostMessage(WM_NULL, 0, 0); // Clean up TrayMenu.DestroyMenu(); return 1; } return 0; }
void CWebInterfaceDlg::ShowTrayMenu() { CMenu menu; menu.LoadMenu (IDM_TRAY); CMenu *pPopup = menu.GetSubMenu (0); SetForegroundWindow (); pPopup->SetDefaultItem (ID_CONFIGURE); CPoint pt; GetCursorPos (&pt); pPopup->TrackPopupMenu (TPM_RIGHTBUTTON | TPM_BOTTOMALIGN | TPM_RIGHTALIGN, pt.x, pt.y, this); menu.DestroyMenu (); }
void CTrayNotifyIcon::SetDefaultMenuItem(UINT uItem, BOOL fByPos) { m_nDefaultMenuItem = uItem; m_bDefaultMenuItemByPos = fByPos; //Also update in the live menu if it is present if (m_Menu.operator HMENU()) { #ifdef _AFX CMenu* pSubMenu = m_Menu.GetSubMenu(0); ATLASSERT(pSubMenu); //Your menu resource has been designed incorrectly pSubMenu->SetDefaultItem(m_nDefaultMenuItem, m_bDefaultMenuItemByPos); #else CMenuHandle subMenu = m_Menu.GetSubMenu(0); ATLASSERT(subMenu.IsMenu()); //Your menu resource has been designed incorrectly subMenu.SetMenuDefaultItem(m_nDefaultMenuItem, m_bDefaultMenuItemByPos); #endif } }
void CFolderListCtrl::OnRButtonDown(UINT nFlags, CPoint point) { CListCtrl::OnRButtonDown(nFlags, point); POSITION selPos = GetFirstSelectedItemPosition(); int nItemPos = -1; if( selPos ) nItemPos = GetNextSelectedItem( selPos ); if( nItemPos >= 0 ) { SetSelectionMark( nItemPos ); CMenu m_ListPopup; m_ListPopup.LoadMenu( IDR_FOLDER_LIST ); CMenu * pListMenu = m_ListPopup.GetSubMenu( 0 ); pListMenu->SetDefaultItem(ID_FILE_EDIT); ClientToScreen( &point ); pListMenu->TrackPopupMenu( TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd() ); } }
void CTrayNotifyIcon::SetMenu(HMENU hMenu) { //Validate our parameters ATLASSERT(hMenu); m_Menu.DestroyMenu(); m_Menu.Attach(hMenu); #ifdef _AFX CMenu* pSubMenu = m_Menu.GetSubMenu(0); ATLASSERT(pSubMenu); //Your menu resource has been designed incorrectly //Make the specified menu item the default (bold font) pSubMenu->SetDefaultItem(m_nDefaultMenuItem, m_bDefaultMenuItemByPos); #else CMenuHandle subMenu = m_Menu.GetSubMenu(0); ATLASSERT(subMenu.IsMenu()); //Your menu resource has been designed incorrectly //Make the specified menu item the default (bold font) subMenu.SetMenuDefaultItem(m_nDefaultMenuItem, m_bDefaultMenuItemByPos); #endif }
/** * タスクトレイメッセージハンドラ */ LRESULT CInspectUsefulToolsDlg::OnNotifyTaskBarIcon(WPARAM,LPARAM lParam) { CMenu cMenu; POINT point; switch (lParam) { case WM_RBUTTONUP: // TrackPopupMenu か TrackPopupMenuEx を呼び出す前に、ウィンドウを // フォアグラウンドウィンドウにしなければならない // (see the MSDN Article ID: Q135788 ) SetForegroundWindow(); if( cMenu.LoadMenu(IDR_POPUPMENU)) { CMenu* pSubMenu = cMenu.GetSubMenu(0); if (pSubMenu != NULL) { pSubMenu->SetDefaultItem( 0, TRUE); GetCursorPos( &point ); pSubMenu->TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this); pSubMenu->DestroyMenu(); } cMenu.DestroyMenu(); } // BUGFIX: 最後に次のクリックに反応できるようにメッセージをポスト // (see the MSDN Article ID: Q135788 ) PostMessage( WM_NULL, 0, 0); break; case WM_LBUTTONDBLCLK: this->ShowWindow(SW_SHOW); this->PostMessage(WM_SYSCOMMAND, SC_RESTORE); break; } return NULL; }
BOOL CTrayNotifyIcon::Create(CWindow* pNotifyWnd, UINT uID, LPCTSTR pszTooltipText, HICON hIcon, UINT nNotifyMessage, UINT uMenuID) #endif { //Validate our parameters ATLASSERT(pNotifyWnd && ::IsWindow(pNotifyWnd->operator HWND())); #ifdef _DEBUG if (GetShellVersion() >= 5) //If on Shell v5 or higher, then use the larger size tooltip { NOTIFYICONDATA_2 dummy; ATLASSERT(_tcslen(pszTooltipText) < sizeof(dummy.szTip)/sizeof(TCHAR)); DBG_UNREFERENCED_LOCAL_VARIABLE(dummy); } else { NOTIFYICONDATA_1 dummy; ATLASSERT(_tcslen(pszTooltipText) < sizeof(dummy.szTip)/sizeof(TCHAR)); DBG_UNREFERENCED_LOCAL_VARIABLE(dummy); } #endif ATLASSERT(hIcon); ATLASSERT(nNotifyMessage >= WM_USER); //Make sure we avoid conflict with other messages //Load up the menu resource which is to be used as the context menu if (!m_Menu.LoadMenu(uMenuID == 0 ? uID : uMenuID)) { ATLASSERT(FALSE); return FALSE; } #ifdef _AFX CMenu* pSubMenu = m_Menu.GetSubMenu(0); if (!pSubMenu) { ATLASSERT(FALSE); //Your menu resource has been designed incorrectly return FALSE; } //Make the specified menu item the default (bold font) pSubMenu->SetDefaultItem(m_nDefaultMenuItem, m_bDefaultMenuItemByPos); #else CMenuHandle subMenu = m_Menu.GetSubMenu(0); if (!subMenu.IsMenu()) { ATLASSERT(FALSE); //Your menu resource has been designed incorrectly return FALSE; } subMenu.SetMenuDefaultItem(m_nDefaultMenuItem, m_bDefaultMenuItemByPos); #endif //Install the hook if (!m_HookWnd.Init(this, pNotifyWnd)) return FALSE; //Call the Shell_NotifyIcon function m_pNotificationWnd = pNotifyWnd; m_NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; m_NotifyIconData.hWnd = pNotifyWnd->operator HWND(); m_NotifyIconData.uID = uID; m_NotifyIconData.uCallbackMessage = nNotifyMessage; m_NotifyIconData.hIcon = hIcon; #if (_MSC_VER >= 1400) _tcscpy_s(m_NotifyIconData.szTip, sizeof(m_NotifyIconData.szTip)/sizeof(TCHAR), pszTooltipText); #else _tcscpy(m_NotifyIconData.szTip, pszTooltipText); #endif m_bCreated = Shell_NotifyIcon(NIM_ADD, reinterpret_cast<PNOTIFYICONDATA>(&m_NotifyIconData)); //Turn on Shell v5 style behaviour if supported if (GetShellVersion() >= 5) SetVersion(NOTIFYICON_VERSION); return m_bCreated; }
void CDownloads_Groups::ShowGrpContextMenu(HTREEITEM hItem, BOOL bAutoDetect) { if (bAutoDetect) { hItem = GetSelectedItem (); if (hItem) { RECT rc; GetItemRect (hItem, &rc, TRUE); m_rbX = rc.left; m_rbY = rc.top; } } m_hContextMenuItem = hItem; if (hItem) { if (hItem == m_hDeleted) { ShowDeletedContextMenu (); return; } if (hItem == m_hHistory || GetParentItem (hItem) == m_hHistory) { ShowHistoryContextMenu (); return; } } CMenu menu; menu.LoadMenu (IDM_GROUP); CMenu *pPopup = menu.GetSubMenu (0); ApplyLanguageToMenu (pPopup); pPopup->SetDefaultItem (ID_GRPPROPERTIES); if (hItem) { if (hItem == m_hAllGroups || IsGroupItem (hItem)) { if (hItem == m_hAllGroups) { pPopup->EnableMenuItem (ID_GRPDELETE, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_OPENGROUPFOLDER, MF_BYCOMMAND | MF_GRAYED); pPopup->ModifyMenu (ID_GRPPROPERTIES, MF_BYCOMMAND, ID_GRPSETROOTFOLDER, LS (L_SETGRPROOTFOLDER)); } if (hItem == m_hOther) { pPopup->EnableMenuItem (ID_GRPDELETE, MF_BYCOMMAND | MF_GRAYED); } } else { pPopup->EnableMenuItem (ID_GRPPROPERTIES, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_GRPDELETE, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_OPENGROUPFOLDER, MF_BYCOMMAND | MF_GRAYED); if (hItem != m_hFilters && hItem != m_hCompleted && hItem != m_hAllGroups) { pPopup->EnableMenuItem (ID_GRPDELETEALLSUCCESSFUL, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_GRPDELETEALLDEADDLDS, MF_BYCOMMAND | MF_GRAYED); } else if (hItem == m_hCompleted) { pPopup->EnableMenuItem (ID_GRPSTARTALL, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_GRPSTOPALL, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_GRPDELETEALL, MF_BYCOMMAND | MF_GRAYED); } } } else { pPopup->EnableMenuItem (ID_GRPPROPERTIES, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_GRPDELETE, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_OPENGROUPFOLDER, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_GRPSTARTALL, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_GRPSTOPALL, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_GRPDELETEALL, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_GRPDELETEALLSUCCESSFUL, MF_BYCOMMAND | MF_GRAYED); pPopup->EnableMenuItem (ID_GRPDELETEALLDEADDLDS, MF_BYCOMMAND | MF_GRAYED); } CPoint pt (m_rbX, m_rbY); ClientToScreen (&pt); m_odmenu.Attach (&menu, FALSE); fsSetImage images [] = { fsSetImage (ID_GRPCREATE, 0), fsSetImage (ID_GRPDELETE, 1), fsSetImage (ID_GRPDELETEALL, 2), fsSetImage (ID_GRPPROPERTIES, 3), }; m_odmenu.SetImages (images, sizeof (images) / sizeof (fsSetImage)); pPopup->TrackPopupMenu (TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_LEFTALIGN, pt.x, pt.y, this); m_odmenu.Detach (); menu.DestroyMenu (); }
BOOL CTrayNotifyIcon::Create(CWindow* pNotifyWnd, UINT uID, LPCTSTR pszTooltipText, LPCTSTR pszBalloonText, LPCTSTR pszBalloonCaption, UINT nTimeout, BalloonStyle style, HICON hIcon, UINT nNotifyMessage, UINT uMenuID, BOOL bNoSound) #endif { //Validate our parameters ATLASSERT(pNotifyWnd && ::IsWindow(pNotifyWnd->operator HWND())); ATLASSERT(GetShellVersion() >= 5); //Only supported on Shell v5 or later #ifdef _DEBUG NOTIFYICONDATA_2 dummy; DBG_UNREFERENCED_LOCAL_VARIABLE(dummy); ATLASSERT(_tcslen(pszTooltipText) < sizeof(dummy.szTip)/sizeof(TCHAR)); ATLASSERT(_tcslen(pszBalloonText) < sizeof(dummy.szInfo)/sizeof(TCHAR)); ATLASSERT(_tcslen(pszBalloonCaption) < sizeof(dummy.szInfoTitle)/sizeof(TCHAR)); ATLASSERT(hIcon); ATLASSERT(nNotifyMessage >= WM_USER); //Make sure we avoid conflict with other messages #endif //Load up the menu resource which is to be used as the context menu if (!m_Menu.LoadMenu(uMenuID == 0 ? uID : uMenuID)) { ATLASSERT(FALSE); return FALSE; } #ifdef _AFX CMenu* pSubMenu = m_Menu.GetSubMenu(0); if (!pSubMenu) { ATLASSERT(FALSE); //Your menu resource has been designed incorrectly return FALSE; } //Make the specified menu item the default (bold font) pSubMenu->SetDefaultItem(m_nDefaultMenuItem, m_bDefaultMenuItemByPos); #else CMenuHandle subMenu = m_Menu.GetSubMenu(0); if (!subMenu.IsMenu()) { ATLASSERT(FALSE); //Your menu resource has been designed incorrectly return FALSE; } //Make the specified menu item the default (bold font) subMenu.SetMenuDefaultItem(m_nDefaultMenuItem, m_bDefaultMenuItemByPos); #endif //Install the hook if (!m_HookWnd.Init(this, pNotifyWnd)) return FALSE; //Call the Shell_NotifyIcon function m_pNotificationWnd = pNotifyWnd; m_NotifyIconData.hWnd = pNotifyWnd->operator HWND(); m_NotifyIconData.uID = uID; m_NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO; m_NotifyIconData.uCallbackMessage = nNotifyMessage; m_NotifyIconData.hIcon = hIcon; #if (_MSC_VER >= 1400) _tcscpy_s(m_NotifyIconData.szTip, sizeof(m_NotifyIconData.szTip)/sizeof(TCHAR), pszTooltipText); _tcscpy_s(m_NotifyIconData.szInfo, sizeof(m_NotifyIconData.szInfo)/sizeof(TCHAR), pszBalloonText); _tcscpy_s(m_NotifyIconData.szInfoTitle, sizeof(m_NotifyIconData.szInfoTitle)/sizeof(TCHAR), pszBalloonCaption); #else _tcscpy(m_NotifyIconData.szTip, pszTooltipText); _tcscpy(m_NotifyIconData.szInfo, pszBalloonText); _tcscpy(m_NotifyIconData.szInfoTitle, pszBalloonCaption); #endif m_NotifyIconData.uTimeout = nTimeout; switch (style) { case Warning: { m_NotifyIconData.dwInfoFlags = NIIF_WARNING; break; } case Error: { m_NotifyIconData.dwInfoFlags = NIIF_ERROR; break; } case Info: { m_NotifyIconData.dwInfoFlags = NIIF_INFO; break; } case None: { m_NotifyIconData.dwInfoFlags = NIIF_NONE; break; } case User: { ATLASSERT(hIcon != NULL); //You forget to provide a user icon m_NotifyIconData.dwInfoFlags = NIIF_USER; break; } default: { ATLASSERT(FALSE); break; } } if (bNoSound) m_NotifyIconData.dwInfoFlags |= NIIF_NOSOUND; m_bCreated = Shell_NotifyIcon(NIM_ADD, reinterpret_cast<PNOTIFYICONDATA>(&m_NotifyIconData)); //Turn on Shell v5 tray icon behaviour SetVersion(NOTIFYICON_VERSION); return m_bCreated; }
void CFilePatchesDlg::OnNMRclickFilelist(NMHDR * /*pNMHDR*/, LRESULT *pResult) { *pResult = 0; if (m_sPath.IsEmpty()) return; CString temp; CMenu popup; POINT point; DWORD ptW = GetMessagePos(); point.x = GET_X_LPARAM(ptW); point.y = GET_Y_LPARAM(ptW); if (!popup.CreatePopupMenu()) return; UINT nFlags = MF_STRING | (m_cFileList.GetSelectedCount()==1 ? MF_ENABLED : MF_DISABLED | MF_GRAYED); temp.LoadString(IDS_PATCH_PREVIEW); popup.AppendMenu(nFlags, ID_PATCHPREVIEW, temp); popup.SetDefaultItem(ID_PATCHPREVIEW, FALSE); temp.LoadString(IDS_PATCH_ALL); popup.AppendMenu(MF_STRING | MF_ENABLED, ID_PATCHALL, temp); nFlags = MF_STRING | (m_cFileList.GetSelectedCount() > 0 ? MF_ENABLED : MF_DISABLED | MF_GRAYED); temp.LoadString(IDS_PATCH_SELECTED); popup.AppendMenu(nFlags, ID_PATCHSELECTED, temp); // if the context menu is invoked through the keyboard, we have to use // a calculated position on where to anchor the menu on if ((point.x == -1) && (point.y == -1)) { CRect rect; GetWindowRect(&rect); point = rect.CenterPoint(); } int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RIGHTBUTTON, point.x, point.y, this, 0); switch (cmd) { case ID_PATCHPREVIEW: if (m_pCallBack) { int nIndex = m_cFileList.GetSelectionMark(); if (m_arFileStates.GetAt(nIndex) == FPDLG_FILESTATE_ERROR) { MessageBox(m_pPatch->GetPatchRejects(nIndex), NULL, MB_ICONERROR); } else if ( m_arFileStates.GetAt(nIndex)!=FPDLG_FILESTATE_PATCHED) { m_pCallBack->PatchFile(m_pPatch->GetStrippedPath(nIndex), m_pPatch->GetContentMods(nIndex), m_pPatch->GetPropMods(nIndex), _T("")); m_ShownIndex = nIndex; m_cFileList.Invalidate(); } } break; case ID_PATCHALL: PatchAll(); break; case ID_PATCHSELECTED: PatchSelected(); break; default: break; } }
void CRelaxReminderDlg::ShowRightClickMenu() { // 在托盘图标上单击鼠标右键,弹出菜单 CMenu oMenu; if (FALSE == oMenu.LoadMenu(IDR_MENU_TRAYMENU)) { return; } CMenu* pPopup = oMenu.GetSubMenu(0); ASSERT(pPopup != NULL); LoadMenuLanguageString(&oMenu); // 设置默认菜单项为“显示悬浮窗” pPopup->SetDefaultItem(ID_MENU_MAIN_WINDOW, FALSE); // “显示悬浮窗”菜单是否选中 oMenu.CheckMenuItem(ID_MENU_MAIN_WINDOW, IsWindowVisible() ? MF_CHECKED : MF_UNCHECKED); // “显示通知栏图标”菜单是否选中 oMenu.CheckMenuItem(ID_MENU_TRAY_ICON, m_bTrayIconVisible ? MF_CHECKED : MF_UNCHECKED); // “暂停”菜单默认为不选中 oMenu.CheckMenuItem(ID_MENU_PAUSE, MF_UNCHECKED); // 处理其它菜单项的显示状态,默认为可用,只需要设置不可用的项 switch (m_tm.GetStatus()) { case STATUS_INIT: oMenu.EnableMenuItem(ID_MENU_SHORT_RELAX, MF_DISABLED | MF_GRAYED); oMenu.EnableMenuItem(ID_MENU_LONG_RELAX, MF_DISABLED | MF_GRAYED); oMenu.EnableMenuItem(ID_MENU_PAUSE, MF_DISABLED | MF_GRAYED); oMenu.EnableMenuItem(ID_MENU_RESET, MF_DISABLED | MF_GRAYED); break; case STATUS_WORK: case STATUS_AUTO_PAUSE: // 有可能在1秒心跳还没到,状态还是AutoPause或AutoReset, case STATUS_AUTO_RESET: // 但在操作菜单时实际可能已经处于工作态了,故这里与工作态使用相同的设置 oMenu.EnableMenuItem(ID_MENU_START_WORK, MF_DISABLED | MF_GRAYED); break; case STATUS_SHORT_RELAX: oMenu.EnableMenuItem(ID_MENU_SHORT_RELAX, MF_DISABLED | MF_GRAYED); oMenu.EnableMenuItem(ID_MENU_LONG_RELAX, MF_DISABLED | MF_GRAYED); oMenu.EnableMenuItem(ID_MENU_PAUSE, MF_DISABLED | MF_GRAYED); break; case STATUS_LONG_RELAX: oMenu.EnableMenuItem(ID_MENU_SHORT_RELAX, MF_DISABLED | MF_GRAYED); oMenu.EnableMenuItem(ID_MENU_LONG_RELAX, MF_DISABLED | MF_GRAYED); oMenu.EnableMenuItem(ID_MENU_PAUSE, MF_DISABLED | MF_GRAYED); break; case STATUS_PAUSE: oMenu.CheckMenuItem(ID_MENU_PAUSE, MF_CHECKED); oMenu.EnableMenuItem(ID_MENU_START_WORK, MF_DISABLED | MF_GRAYED); oMenu.EnableMenuItem(ID_MENU_SHORT_RELAX, MF_DISABLED | MF_GRAYED); oMenu.EnableMenuItem(ID_MENU_LONG_RELAX, MF_DISABLED | MF_GRAYED); break; case STATUS_RESET: oMenu.EnableMenuItem(ID_MENU_PAUSE, MF_DISABLED | MF_GRAYED); oMenu.EnableMenuItem(ID_MENU_RESET, MF_DISABLED | MF_GRAYED); break; default: break; } // 确定鼠标位置以便在该位置附近显示菜单 CPoint Point; GetCursorPos(&Point); SetForegroundWindow(); pPopup->TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, Point.x, Point.y, this); }
void CFilePatchesDlg::OnNMRclickFilelist(NMHDR * /*pNMHDR*/, LRESULT *pResult) { *pResult = 0; if (m_sPath.IsEmpty()) return; CString temp; CMenu popup; POINT point; DWORD ptW = GetMessagePos(); point.x = GET_X_LPARAM(ptW); point.y = GET_Y_LPARAM(ptW); if (popup.CreatePopupMenu()) { UINT nFlags; nFlags = MF_STRING | (m_cFileList.GetSelectedCount()==1 ? MF_ENABLED : MF_DISABLED | MF_GRAYED); temp.LoadString(IDS_PATCH_REVIEW); popup.AppendMenu(nFlags, ID_PATCH_REVIEW, temp); popup.SetDefaultItem(ID_PATCH_REVIEW, FALSE); temp.LoadString(IDS_PATCH_PREVIEW); popup.AppendMenu(nFlags, ID_PATCHPREVIEW, temp); temp.LoadString(IDS_PATCH_ALL); popup.AppendMenu(MF_STRING | MF_ENABLED, ID_PATCHALL, temp); nFlags = MF_STRING | (m_cFileList.GetSelectedCount()>0 ? MF_ENABLED : MF_DISABLED | MF_GRAYED); temp.LoadString(IDS_PATCH_SELECTED); popup.AppendMenu(nFlags, ID_PATCHSELECTED, temp); // if the context menu is invoked through the keyboard, we have to use // a calculated position on where to anchor the menu on if ((point.x == -1) && (point.y == -1)) { CRect rect; GetWindowRect(&rect); point = rect.CenterPoint(); } bool bReview=false; int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0); switch (cmd) { case ID_PATCH_REVIEW: bReview = true; //go through case case ID_PATCHPREVIEW: { if (m_pCallBack) { int nIndex = m_cFileList.GetSelectionMark(); if ( m_arFileStates.GetAt(nIndex)!=FPDLG_FILESTATE_PATCHED) { m_pCallBack->PatchFile(GetFullPath(nIndex), m_pPatch->GetRevision(nIndex),false,bReview); } } } break; case ID_PATCHALL: { if (m_pCallBack) { CSysProgressDlg progDlg; progDlg.SetTitle(IDR_MAINFRAME); progDlg.SetShowProgressBar(true); progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PATCH_ALL))); progDlg.ShowModeless(m_hWnd); for (int i=0; i<m_arFileStates.GetCount() && !progDlg.HasUserCancelled(); i++) { if (m_arFileStates.GetAt(i)!= FPDLG_FILESTATE_PATCHED) { progDlg.SetLine(2, GetFullPath(i), true); m_pCallBack->PatchFile(GetFullPath(i), m_pPatch->GetRevision(i), TRUE); } progDlg.SetProgress64(i, m_arFileStates.GetCount()); } progDlg.Stop(); } } break; case ID_PATCHSELECTED: { if (m_pCallBack) { CSysProgressDlg progDlg; progDlg.SetTitle(IDR_MAINFRAME); progDlg.SetShowProgressBar(true); progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PATCH_SELECTED))); progDlg.ShowModeless(m_hWnd); // The list cannot be sorted by user, so the order of the // items in the list is identical to the order in the array // m_arFileStates. int selCount = m_cFileList.GetSelectedCount(); int count = 1; POSITION pos = m_cFileList.GetFirstSelectedItemPosition(); int index; while (((index = m_cFileList.GetNextSelectedItem(pos)) >= 0) && (!progDlg.HasUserCancelled())) { if (m_arFileStates.GetAt(index)!= FPDLG_FILESTATE_PATCHED) { progDlg.SetLine(2, GetFullPath(index), true); m_pCallBack->PatchFile(GetFullPath(index), m_pPatch->GetRevision(index), TRUE); } progDlg.SetProgress64(count++, selCount); } progDlg.Stop(); } } break; default: break; } } }