Here. This should work on 64-bit compilers.
Code: (Select All)
DEFLNG A-Z
OPTION _EXPLICIT
$IF 32BIT THEN
$ERROR 32-bit compilers not supported!
$END IF
CONST NULL = 0
CONST MIIM_STATE = &H1
CONST MIIM_ID = &H2
CONST MIIM_TYPE = &H10
CONST MFT_SEPARATOR = &H800
CONST MFT_STRING = &H0
CONST MFS_ENABLED = &H0
CONST MFS_CHECKED = &H8
CONST HWND_TOPMOST = -1
CONST HWND_NOTOPMOST = -2
CONST SWP_NOMOVE = &H2
CONST SWP_NOSIZE = &H1
TYPE MENUITEMINFO
AS _UNSIGNED LONG cbSize
AS _UNSIGNED LONG fMask
AS _UNSIGNED LONG fType
AS _UNSIGNED LONG fState
AS _UNSIGNED LONG wID
AS STRING * 4 __padding1
AS _UNSIGNED _OFFSET hSubMenu
AS _UNSIGNED _OFFSET hbmpChecked
AS _UNSIGNED _OFFSET hbmpUnchecked
AS _UNSIGNED _OFFSET dwItemData
AS _UNSIGNED _OFFSET dwTypeData ' str ptr
AS _UNSIGNED LONG cch
AS STRING * 4 __padding2
AS _UNSIGNED _OFFSET hbmpItem
END TYPE
DECLARE DYNAMIC LIBRARY "user32"
FUNCTION FindWindow~%& ALIAS FindWindowA (lpClassName AS STRING, lpWindowName AS STRING)
FUNCTION CreateMenu~%&
FUNCTION DrawMenuBar& (BYVAL hWnd AS _UNSIGNED _OFFSET)
FUNCTION SetMenu& (BYVAL hWnd AS _UNSIGNED _OFFSET, BYVAL hMenu AS _UNSIGNED _OFFSET)
FUNCTION InsertMenuItem& ALIAS InsertMenuItemA (BYVAL hMenu AS _UNSIGNED _OFFSET, BYVAL item AS _UNSIGNED LONG, BYVAL fByPosition AS LONG, BYVAL lpmi AS _UNSIGNED _OFFSET)
FUNCTION GetMenuItemCount& (BYVAL hMenu AS _UNSIGNED _OFFSET)
FUNCTION GetMenuItemInfo& ALIAS GetMenuItemInfoA (BYVAL hMenu AS _UNSIGNED _OFFSET, BYVAL item AS _UNSIGNED LONG, BYVAL fByPosition AS LONG, BYVAL lpmii AS _UNSIGNED _OFFSET)
END DECLARE
DIM MenuItem AS MENUITEMINFO, BlankMenuItem AS MENUITEMINFO
DIM TypeData AS STRING * 1000
_TITLE "Menu bar API demo"
DIM hWnd AS _UNSIGNED _OFFSET: hWnd = _WINDOWHANDLE 'FindWindow(0, "Menu bar API demo" + CHR$(0))
DIM hMenu AS _UNSIGNED _OFFSET: hMenu = CreateMenu: BlankMenuItem.cbSize = LEN(BlankMenuItem)
COLOR 7, 1
'Add a separator bar
DIM count AS LONG: count = GetMenuItemCount(hMenu): PRINT "MenuItemCount:"; count
MenuItem = BlankMenuItem
MenuItem.fMask = MIIM_ID OR MIIM_TYPE
MenuItem.fType = MFT_SEPARATOR
MenuItem.wID = count
IF InsertMenuItem(hMenu, count, 1, _OFFSET(MenuItem)) THEN PRINT "Successfully added menu item!" ELSE PRINT "Failed to add menu item!": END
'Add a button
MenuItem = BlankMenuItem
count = GetMenuItemCount(hMenu): PRINT "MenuItemCount:"; count
MenuItem.fMask = MIIM_STATE OR MIIM_ID OR MIIM_TYPE
MenuItem.fType = MFT_STRING
MenuItem.fState = MFS_ENABLED
MenuItem.wID = count
TypeData = "&Fire Laser!" + CHR$(NULL)
MenuItem.dwTypeData = _OFFSET(TypeData)
MenuItem.cch = LEN(MenuItem.dwTypeData)
DIM MyButton AS _UNSIGNED LONG: MyButton = MenuItem.wID
IF InsertMenuItem(hMenu, count, 1, _OFFSET(MenuItem)) THEN PRINT "Successfully added menu item!" ELSE PRINT "Failed to add menu item!": END
IF SetMenu(hWnd, hMenu) THEN PRINT "Successfully set menu!": PRINT "Menu handle is:"; hMenu ELSE PRINT "Failed to set menu!": END
DIM AS LONG prev_state, new_state, ok
DO
_LIMIT 70
prev_state = new_state
ok = GetMenuItemInfo(hMenu, MyButton, 1, _OFFSET(MenuItem))
new_state = MenuItem.fState AND 128
IF prev_state = 0 AND new_state <> 0 THEN PRINT "Ouch! ";
LOOP WHILE INKEY$ = ""
END