What I'm trying to do is handle the %WM_INITMENUPOPUP commands and dynamically enable/disable menu items on the fly based on available clipboard formats. However:
File / Edit / View / Help
If I should happen to change things up and for some quack reason stick a new top level menu item in front of Edit, that means my Edit is no longer the #1 zero-based relative position menu item. Currently, it seems in order to do this, you need a MenuHitTest function:
:coffee:
Not a bad construct for studying the SDK for a while, though if there IS a GetParentMenu function, or a menu function which gets the parent, I'm not finding it.
Note: it's not %100 percent necessary to return the SubMenu's handle, if the strings match, then the SubMenu will be the same thing as the wParam, which should also be checked if you're crazy enough to nest menu names.
In which case you would also do:
Otherwise a %TRUE return will suffice. I suppose this can be fleshed out further to gain the parent of SubSubMenu's.
- Parameters
- wParam
- Handle to the drop-down menu or submenu.
- lParam
- The low-order word specifies the zero-based relative position of the menu item that opens the drop-down menu or submenu.
- The high-order word indicates whether the drop-down menu is the window menu. If the menu is the window menu, this parameter is TRUE; otherwise, it is FALSE.
- wParam
File / Edit / View / Help
If I should happen to change things up and for some quack reason stick a new top level menu item in front of Edit, that means my Edit is no longer the #1 zero-based relative position menu item. Currently, it seems in order to do this, you need a MenuHitTest function:
Code:
FUNCTION MenuHitTest(hDialog AS DWORD, wParam AS DWORD, lParam AS DWORD, _ mString AS STRING) AS LONG LOCAL hMenu, mIndex, mCount, myMenu, sCount AS DWORD LOCAL aString AS ASCIIZ * 80 IF ISFALSE HI(WORD, lParam) THEN hMenu = GetMenu(hDialog) mCount = GetMenuItemCount(hMenu) mIndex = LO(WORD, lParam) IF mIndex < mCount THEN sCount = GetMenuString(hMenu, mIndex, aString, 79, %MF_BYPOSITION) IF sCount > 0 THEN IF mString = aString THEN MenuHitTest = GetSubMenu(hMenu, mIndex) END IF END IF END IF END IF END FUNCTION
Code:
CASE %WM_INITMENUPOPUP IF ISTRUE MenuHitTest(CB.HNDL, CB.WPARAM, CB.LPARAM, "Edit") THEN ' then do stuff END IF
Note: it's not %100 percent necessary to return the SubMenu's handle, if the strings match, then the SubMenu will be the same thing as the wParam, which should also be checked if you're crazy enough to nest menu names.

In which case you would also do:
Code:
myMenu = GetSubMenu(hMenu, mIndex) IF myMenu = wParam THEN MenuHitTest = myMenu END IF
Comment