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

Method CreateHandle

source/script_menu.cpp:923–969  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

921
922
923ResultType UserMenu::CreateHandle()
924// Menu bars require non-popup menus (CreateMenu vs. CreatePopupMenu). Rather than maintain two
925// different types of HMENUs on the rare chance that a script might try to use a menu both as
926// a popup and a menu bar, it seems best to have only one type to keep the code simple and reduce
927// resources used for the menu. This is reflected in MenuCreate() and MenuBarCreate(), which
928// create the UserMenu with the appropriate value for mMenuType.
929{
930 if (mMenu)
931 return OK;
932 if ( !(mMenu = (mMenuType == MENU_TYPE_BAR) ? CreateMenu() : CreatePopupMenu()) )
933 // Failure is rare, so no error msg here (caller can, if it wants).
934 return FAIL;
935
936 // It seems best not to have a mandatory EXIT item added to the bottom of the tray menu
937 // because omitting it allows the tray icon to be shown even when the user wants it to
938 // have no menu at all (i.e. avoids the need for #NoTrayIcon just to disable the showing
939 // of the menu). If it was done, it should not be done here because calling Menu.Handle
940 // prior to adding items would have the effect of inserting EXIT at the top.
941 //if (!mMenuItemCount)
942 //{
943 // AppendMenu(mTrayMenu->mMenu, MF_STRING, ID_TRAY_EXIT, "E&xit");
944 // return OK;
945 //}
946
947 // Now append all of the user defined items:
948 UserMenuItem *mi;
949 for (mi = mFirstMenuItem; mi; mi = mi->mNextMenuItem)
950 InternalAppendMenu(mi);
951
952 if (mDefault)
953 // This also automatically ensures that only one is default at a time:
954 SetMenuDefaultItem(mMenu, mDefault->mMenuID, FALSE);
955
956 // Apply background color if this menu has a non-standard one. If this menu has submenus,
957 // they will be individually given their own background color when created via CreateHandle(),
958 // which is why false is passed:
959 ApplyColor(false);
960
961 // L17: Apply default style to merge checkmark/icon columns in menu.
962 MENUINFO menu_info;
963 menu_info.cbSize = sizeof(MENUINFO);
964 menu_info.fMask = MIM_STYLE;
965 menu_info.dwStyle = MNS_CHECKORBMP;
966 SetMenuInfo(mMenu, &menu_info);
967
968 return OK;
969}
970
971
972

Callers 2

SetMenuMethod · 0.80
InternalAppendMenuMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected