HMENU ProcessSubMenu(iteminfo *info, UINT idCmdFirst) { HMENU hSubmenu = CreatePopupMenu(); int i = 0; while (info[i].id != -1) { MENUITEMINFO mii = { sizeof(MENUITEMINFO) }; mii.fMask = MIIM_STRING | MIIM_ID; mii.wID = info[i].id + idCmdFirst; mii.dwTypeData = info[i].text; if (info[i].subitems != nullptr) { mii.fMask |= MIIM_SUBMENU; mii.hSubMenu = ProcessSubMenu(info[i].subitems, idCmdFirst); } InsertMenuItem(hSubmenu, i++, TRUE, &mii); } return hSubmenu; }
IFACEMETHODIMP CContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { // If uFlags include CMF_DEFAULTONLY then we should not do anything. if (CMF_DEFAULTONLY & uFlags) return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(0)); MENUITEMINFO mii = { sizeof(mii) }; mii.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU; mii.wID = idCmdFirst + curid; mii.dwTypeData = L"KENSSharp"; mii.hSubMenu = ProcessSubMenu(rootmenu, idCmdFirst); if (!InsertMenuItem(hMenu, indexMenu, TRUE, &mii)) { return HRESULT_FROM_WIN32(GetLastError()); } // Return an HRESULT value with the severity set to SEVERITY_SUCCESS. // Set the code value to the offset of the largest command identifier // that was assigned, plus one (1). return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(curid + 1)); }
int HMenu::ProcessKey(int Key) { SelectPos=0; for (int i=0; i<ItemCount; i++) { if (Item[i].Selected) { SelectPos=i; break; } } switch (Key) { case KEY_ALTF9: case KEY_RALTF9: FrameManager->ProcessKey(KEY_ALTF9); break; case KEY_OP_PLAINTEXT: { const wchar_t *str = eStackAsString(); if (!*str) return FALSE; Key=*str; break; } case KEY_NONE: case KEY_IDLE: { return FALSE; } case KEY_F1: { ShowHelp(); return TRUE; } case KEY_NUMENTER: case KEY_ENTER: case KEY_DOWN: case KEY_NUMPAD2: { if (Item[SelectPos].SubMenu) { ProcessSubMenu(Item[SelectPos].SubMenu,Item[SelectPos].SubMenuSize, Item[SelectPos].SubMenuHelp,ItemX[SelectPos], Y1+1,VExitCode); if (VExitCode!=-1) { EndLoop=TRUE; Modal::ExitCode=SelectPos; } return TRUE; } return FALSE; } case KEY_TAB: { Item[SelectPos].Selected=0; /* Кусок для "некрайних" меню - прыжок к меню пассивной панели */ if (SelectPos && SelectPos != ItemCount-1) { if (CtrlObject->Cp()->ActivePanel==CtrlObject->Cp()->RightPanel) SelectPos=0; else SelectPos=ItemCount-1; } else /**/ { if (!SelectPos) SelectPos=ItemCount-1; else SelectPos=0; } Item[SelectPos].Selected=1; ShowMenu(); return TRUE; } case KEY_ESC: case KEY_F10: { EndLoop=TRUE; Modal::ExitCode=-1; return FALSE; } case KEY_HOME: case KEY_NUMPAD7: case KEY_CTRLHOME: case KEY_CTRLNUMPAD7: case KEY_RCTRLHOME: case KEY_RCTRLNUMPAD7: case KEY_CTRLPGUP: case KEY_CTRLNUMPAD9: case KEY_RCTRLPGUP: case KEY_RCTRLNUMPAD9: { Item[SelectPos].Selected=0; Item[0].Selected=1; SelectPos=0; ShowMenu(); return TRUE; } case KEY_END: case KEY_NUMPAD1: case KEY_CTRLEND: case KEY_CTRLNUMPAD1: case KEY_RCTRLEND: case KEY_RCTRLNUMPAD1: case KEY_CTRLPGDN: case KEY_CTRLNUMPAD3: case KEY_RCTRLPGDN: case KEY_RCTRLNUMPAD3: { Item[SelectPos].Selected=0; Item[ItemCount-1].Selected=1; SelectPos=ItemCount-1; ShowMenu(); return TRUE; } case KEY_LEFT: case KEY_NUMPAD4: case KEY_MSWHEEL_LEFT: { Item[SelectPos].Selected=0; if (--SelectPos<0) SelectPos=ItemCount-1; Item[SelectPos].Selected=1; ShowMenu(); return TRUE; } case KEY_RIGHT: case KEY_NUMPAD6: case KEY_MSWHEEL_RIGHT: { Item[SelectPos].Selected=0; if (++SelectPos==ItemCount) SelectPos=0; Item[SelectPos].Selected=1; ShowMenu(); return TRUE; } default: { for (int i=0; i<ItemCount; i++) { if (IsKeyHighlighted(Item[i].Name,Key,FALSE)) { Item[SelectPos].Selected=0; Item[i].Selected=1; SelectPos=static_cast<int>(i); ShowMenu(); ProcessKey(KEY_ENTER); return TRUE; } } for (int i=0; i<ItemCount; i++) { if (IsKeyHighlighted(Item[i].Name,Key,TRUE)) { Item[SelectPos].Selected=0; Item[i].Selected=1; SelectPos=static_cast<int>(i); ShowMenu(); ProcessKey(KEY_ENTER); return TRUE; } } return FALSE; } } return FALSE; }