MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / InternalAppendMenu

Method InternalAppendMenu

source/script_menu.cpp:518–552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

516
517
518ResultType UserMenu::InternalAppendMenu(UserMenuItem *mi, UserMenuItem *aInsertBefore)
519// Appends an item to mMenu and and ensures the new item's ID is set.
520{
521 MENUITEMINFO mii;
522 mii.cbSize = sizeof(mii);
523 mii.fMask = MIIM_ID | MIIM_FTYPE | MIIM_STRING | MIIM_STATE;
524 mii.wID = mi->mMenuID;
525 mii.fType = mi->mMenuType;
526 mii.dwTypeData = mi->mName;
527 mii.fState = mi->mMenuState;
528 if (mi->mSubmenu)
529 {
530 // Ensure submenu is created so that its handle can be used below.
531 if (!mi->mSubmenu->CreateHandle())
532 return FAIL;
533 mii.fMask |= MIIM_SUBMENU;
534 mii.hSubMenu = mi->mSubmenu->mMenu;
535 }
536 if (mi->mBitmap)
537 {
538 mii.fMask |= MIIM_BITMAP;
539 mii.hbmpItem = mi->mBitmap;
540 }
541 UINT insert_at;
542 BOOL by_position;
543 if (aInsertBefore)
544 insert_at = aInsertBefore->mMenuID, by_position = FALSE;
545 else
546 insert_at = GetMenuItemCount(mMenu), by_position = TRUE;
547 // Although AppendMenu() ignores the ID when adding a separator and provides no way to
548 // specify the ID when adding a submenu, that is purely a limitation of AppendMenu().
549 // Using InsertMenuItem() instead allows us to always set the ID, which simplifies
550 // identifying separator and submenu items later on.
551 return InsertMenuItem(mMenu, insert_at, by_position, &mii) ? OK : FAIL;
552}
553
554
555

Callers

nothing calls this directly

Calls 1

CreateHandleMethod · 0.80

Tested by

no test coverage detected