LRESULT CChildFrame::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { uMsg, wParam, lParam, bHandled; bHandled = FALSE; POINT ptScr = { 0 }; ptScr.x = GET_X_LPARAM(lParam); ptScr.y = GET_Y_LPARAM(lParam); { POINT ptLoc = ptScr; DWORD dwStyle = m_wndCatalog.GetStyle(); if(WS_VISIBLE != (dwStyle & WS_VISIBLE)) return S_OK; RECT rc; m_wndCatalog.GetClientRect(&rc); // 将屏幕坐标转换成指定窗口的相对坐标 m_wndCatalog.ScreenToClient(&ptLoc); // 鼠标指针是否在 TreeView 窗口内 if (::PtInRect(&rc, ptLoc)) { UINT flags = 0; m_pData = m_wndCatalog.HitTest(ptLoc, &flags); if (FALSE == m_pData.IsNull()) { TREE_ITEM_DATA * pTmp = (TREE_ITEM_DATA *)m_pData.GetData(); CMenuHandle mnuPopUp; CMenu mnuTemp; mnuTemp.LoadMenu(IDR_MENU_EXPORT); mnuPopUp = mnuTemp.GetSubMenu(0); if (pTmp->dwStgType == STGTY_STORAGE) { mnuPopUp.EnableMenuItem(ID_FILE_ADD_STG, MF_BYCOMMAND|MF_ENABLED); mnuPopUp.EnableMenuItem(ID_FILE_ADD_STM, MF_BYCOMMAND|MF_ENABLED); } mnuPopUp.TrackPopupMenu(0, ptScr.x, ptScr.y, *this); return 0; } } } return 0; }
void CMainFrame::pUpdateMenuItems() { BOOL fSuccess(FALSE); if (!ndas::UpdateDeviceList()) { // warning device list update failed. } if (!ndas::UpdateLogicalDeviceList()) { // warning logical device list update failed. } m_taskbarMenu.ClearItemStringData(); BOOL showText = TRUE; pGetAppConfigValue(_T("ShowDeviceStatusText"), &showText); m_taskbarMenu.ShowDeviceStatusText(showText); CMenuHandle taskBarRootMenu; taskBarRootMenu.LoadMenu(IDR_TASKBAR); if (pGetAppConfigBOOL(_T("ShowUnmountAll"), FALSE)) { ndas::LogicalDeviceConstIterator itr = std::find_if( m_NdasLogDevices.begin(), m_NdasLogDevices.end(), ndas::LogicalDeviceMounted()); if (m_NdasLogDevices.end() != itr) { // There is a mounted logical device taskBarRootMenu.EnableMenuItem( IDR_UNMOUNT_ALL, MF_BYCOMMAND | MFS_ENABLED); } else { // There is no mounted logical device taskBarRootMenu.EnableMenuItem( IDR_UNMOUNT_ALL, MF_BYCOMMAND | MFS_DISABLED); } // do not remove menu } else { // otherwise remove menu taskBarRootMenu.RemoveMenu(IDR_UNMOUNT_ALL, MF_BYCOMMAND); } CMenuHandle taskBarMenu = ::GetSubMenu(taskBarRootMenu,0); MENUINFO mi = {0}; mi.cbSize = sizeof(MENUINFO); mi.fMask = MIM_STYLE; fSuccess = taskBarMenu.GetMenuInfo(&mi); ATLASSERT(fSuccess); mi.cbSize = sizeof(MENUINFO); mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS; mi.dwStyle |= MNS_NOTIFYBYPOS | MNS_CHECKORBMP; fSuccess = taskBarMenu.SetMenuInfo(&mi); ATLASSERT(fSuccess); if (m_NdasDevices.empty()) { CMenuItemInfo mii; CString strMenuText = MAKEINTRESOURCE(IDS_NO_DEVICE); mii.fMask = MIIM_ID | MIIM_STRING | MIIM_STATE; mii.dwTypeData = (LPTSTR)((LPCTSTR)strMenuText); mii.wID = IDR_NDAS_DEVICE_NONE; mii.fState = MFS_DISABLED | MFS_UNHILITE; fSuccess = taskBarMenu.InsertMenuItem(0, TRUE, &mii); ATLASSERT(fSuccess); } else { std::for_each( m_NdasDevices.begin(), m_NdasDevices.end(), NdasDeviceMenuItemCreator(m_taskbarMenu, taskBarMenu)); } CMenu existingTaskbarMenu = m_taskbarIcon.m_hMenu; m_taskbarIcon.m_hMenu = taskBarRootMenu; }