void ptToolBox::execContextMenu(const QPoint APos) { createMenuActions(); // build the menu entries QMenu hMenu(nullptr); hMenu.setPalette(Theme->menuPalette()); hMenu.setStyle(Theme->style()); if (FFilter->flags() & ptFilterBase::FilterIsBlockable) { hMenu.addAction(FBlockAction); if (FFilter->isBlocked()) { FBlockAction->setText(tr("All&ow")); FBlockAction->setIcon(QIcon(*Theme->ptIconCircleGreen)); } else { FBlockAction->setText(tr("Bl&ock")); FBlockAction->setIcon(QIcon(*Theme->ptIconCircleRed)); } } if (FFilter->flags() & ptFilterBase::FilterHasDefault) { hMenu.addSeparator(); hMenu.addAction(FResetAction); } if (FFilter->flags() & ptFilterBase::FilterIsSaveable) { hMenu.addSeparator(); hMenu.addAction(FSaveAction); hMenu.addAction(FAppendAction); } if (FFilter->flags() & ptFilterBase::FilterIsFavouriteable) { hMenu.addSeparator(); hMenu.addAction(FFavAction); if (FFilter->isFavourite()) { FFavAction->setText(tr("Remove from &favourites")); FFavAction->setIcon(QIcon(*Theme->ptIconStarGrey)); } else { FFavAction->setText(tr("Add to &favourites")); FFavAction->setIcon(QIcon(*Theme->ptIconStar)); } } if (FFilter->flags() & ptFilterBase::FilterIsHideable) { hMenu.addSeparator(); hMenu.addAction(FHideAction); } hMenu.exec(APos); }
void CMainFrame::OnMenuCommand(WPARAM wParam, HMENU hMenuHandle) { if (!::IsMenu(hMenuHandle)) { ATLTRACE("Invalid menu handle: %p.\n", hMenuHandle); return; } CMenuHandle hMenu(hMenuHandle); INT nPos = (INT) wParam; CMenuItemInfo mii; mii.fMask = MIIM_DATA | MIIM_ID; BOOL fSuccess = hMenu.GetMenuItemInfo(nPos, TRUE, &mii); if (!fSuccess) { ATLTRACE("OnMenuCommand: GetMenuItemInfo failed.\n"); return; } DWORD slotNo = static_cast<DWORD>(LOWORD(mii.dwItemData)); NDAS_LOGICALDEVICE_ID lun = static_cast<NDAS_LOGICALDEVICE_ID>(mii.dwItemData); switch (mii.wID) { case IDR_SHOW_DEVICE_PROPERTIES: OnCmdShowDeviceProperties(slotNo); break; case IDR_ENABLE_DEVICE: OnCmdEnableDevice(slotNo); break; case IDR_DISABLE_DEVICE: OnCmdDisableDevice(slotNo); break; case IDR_UNREGISTER_DEVICE: OnCmdUnregisterDevice(slotNo); break; case IDR_RESET_DEVICE: OnCmdResetDevice(slotNo); break; case IDR_NDD_MOUNT_RW: OnCmdMountLogicalUnit(lun, TRUE); break; case IDR_NDD_MOUNT_RO: OnCmdMountLogicalUnit(lun, FALSE); break; case IDR_NDD_UNMOUNT: OnCmdDismountLogicalUnit(lun); break; default: // // Reroute the message // PostMessage(WM_COMMAND, mii.wID, NULL); break; } }
void CMainFrame::OnMenuCommand(WPARAM wParam, HMENU hMenuHandle) { if (!::IsMenu(hMenuHandle)) { ATLTRACE("Invalid menu handle: %p.\n", hMenuHandle); return; } CMenuHandle hMenu(hMenuHandle); INT nPos = (INT) wParam; CMenuItemInfo mii; mii.fMask = MIIM_DATA | MIIM_ID; BOOL fSuccess = hMenu.GetMenuItemInfo(nPos, TRUE, &mii); if (!fSuccess) { ATLTRACE("OnMenuCommand: GetMenuItemInfo failed.\n"); return; } if (IDR_SHOW_DEVICE_PROPERTIES == mii.wID) { DWORD dwSlotNo = static_cast<DWORD>(LOWORD(mii.dwItemData)); OnCmdShowDeviceProperties(dwSlotNo); } else if (IDR_ENABLE_DEVICE == mii.wID) { DWORD dwSlotNo = static_cast<DWORD>(LOWORD(mii.dwItemData)); OnCmdEnableDevice(dwSlotNo); } else if (IDR_DISABLE_DEVICE == mii.wID) { DWORD dwSlotNo = static_cast<DWORD>(LOWORD(mii.dwItemData)); OnCmdDisableDevice(dwSlotNo); } else if (IDR_UNREGISTER_DEVICE == mii.wID) { DWORD dwSlotNo = static_cast<DWORD>(LOWORD(mii.dwItemData)); OnCmdUnregisterDevice(dwSlotNo); } else if (IDR_RESET_DEVICE == mii.wID) { DWORD dwSlotNo = static_cast<DWORD>(LOWORD(mii.dwItemData)); OnCmdResetDevice(dwSlotNo); } else if (IDR_NDD_MOUNT_RW == mii.wID) { NDAS_LOGICALDEVICE_ID logDevId = static_cast<NDAS_LOGICALDEVICE_ID>(mii.dwItemData); OnCmdMountDeviceRW(logDevId); } else if (IDR_NDD_MOUNT_RO == mii.wID) { NDAS_LOGICALDEVICE_ID logDevId = static_cast<NDAS_LOGICALDEVICE_ID>(mii.dwItemData); OnCmdMountDeviceRO(logDevId); } else if (IDR_NDD_UNMOUNT == mii.wID) { NDAS_LOGICALDEVICE_ID logDevId = static_cast<NDAS_LOGICALDEVICE_ID>(mii.dwItemData); OnCmdUnmountDevice(logDevId); } else { // // Reroute the message // PostMessage(WM_COMMAND, mii.wID, NULL); } // for Windows 98/Me // int nPos = HIWORD(wParam); // UINT wId = hMenu.GetMenuItemID(nPos); // ATLTRACE("Menu ID = %d\n"); // PostMessage(WM_COMMAND, MAKEWORD(0, wId), NULL); // SetMsgHandled(TRUE); }