I presume you never saw my edited version of CrashX's menu system but anyway, it's a lot more user-friendly because it taps into the message queue and checks for clicks/etc. Have a look because you might want to adopt an approach more similar to this because it checks for clicks before popping up the menu.
`---------------------------------------
` Complete Window Menu System ( DBPRO )
`
` Written By Niranjan Balachandra (CrashX)
` Edited and Improved by Exeat
`---------------------------------------
SYNC ON
SET WINDOW ON
Type Point_t
x as integer
y as integer
EndType
Type Msg_t
hwnd as dword
msg as dword
wparam as dword
lparam as dword
time as dword
pt as Point_t
EndType
msgPtr = make memory ( 28 )
msg as Msg_T
hwnd as dword
`Constants used for AppendMenuA
#CONSTANT MF_BYCOMMAND 0
#CONSTANT MF_BYPOSITION 1024
#CONSTANT MF_SEPARATOR 2048
#CONSTANT MF_ENABLED 0
#CONSTANT MF_GRAYED 1
#CONSTANT MF_DISABLED 2
#CONSTANT MF_UNCHECKED 0
#CONSTANT MF_CHECKED 8
#CONSTANT MF_USECHECKBITMAPS 512
#CONSTANT MF_STRING 0
#CONSTANT MF_BITMAP 4
#CONSTANT MF_OWNERDRAW 256
#CONSTANT MF_POPUP 16
#CONSTANT MF_MENUBARBREAK 32
#CONSTANT MF_MENUBREAK 64
#CONSTANT MF_UNHILITE 0
#CONSTANT MF_HILITE 128
`Constants used for TrackPopupMenu
#CONSTANT TPM_LEFTBUTTON 0
#CONSTANT TPM_RIGHTBUTTON 2
#CONSTANT TPM_LEFTALIGN 0
#CONSTANT TPM_CENTERALIGN 4
#CONSTANT TPM_RIGHTALIGN 8
#CONSTANT TPM_RECURSE 1
#CONSTANT TPM_HORPOSANIMATION 1024
#CONSTANT TPM_HORNEGANIMATION 2048
#CONSTANT TPM_VERPOSANIMATION 4096
#CONSTANT TPM_VERNEGANIMATION 8192
`WINVER >= 0x0400
#CONSTANT TPM_TOPALIGN 0
#CONSTANT TPM_VCENTERALIGN 16
#CONSTANT TPM_BOTTOMALIGN 32
#CONSTANT TPM_HORIZONTAL 0
#CONSTANT TPM_VERTICAL 64
#CONSTANT TPM_NONOTIFY 128
#CONSTANT TPM_RETURNCMD 256
`Makes adjuments to display menu based on position of window
#CONSTANT MENU_ADJUSTMENT_X 4
#CONSTANT MENU_ADJUSTMENT_Y 27
`Load Dll
LOAD DLL "user32.dll",1
hWnd = CALL DLL(1,"GetActiveWindow")
`Menu Constants
#CONSTANT FILE 10
#CONSTANT FILE_OPEN 11
#CONSTANT FILE_SAVE 12
#CONSTANT FILE_RECENT_DOCUMENTS 13
#CONSTANT FILE_DOCUMENT_1 14
#CONSTANT FILE_DOCUMENT_2 15
#CONSTANT FILE_DOCUMENT_3 16
#CONSTANT FILE_QUIT 17
#CONSTANT EDIT 20
#CONSTANT EDIT_CUT 21
#CONSTANT EDIT_COPY 22
#CONSTANT EDIT_PASTE 23
#CONSTANT HELP 30
#CONSTANT HELP_ABOUT 31
#CONSTANT OPTION_CUT 40
#CONSTANT OPTION_COPY 41
#CONSTANT OPTION_PASTE 42
#CONSTANT OPTION_SELECTALL 43
#CONSTANT OPTION_UNDO 44
#CONSTANT OPTION_REDO 45
#CONSTANT OPTION_CHECKED 46
`Create File Menu Popup
hMenuFilePopup = CALL DLL(1,"CreatePopupMenu" )
hMenuTempPopup = CALL DLL(1,"CreatePopupMenu" )
CALL DLL 1,"AppendMenuA",hMenuFilePopup,MF_ENABLED,FILE_OPEN,"&Open"
CALL DLL 1,"AppendMenuA",hMenuFilePopup,MF_GRAYED,FILE_SAVE,"&Save"
CALL DLL 1,"AppendMenuA",hMenuFilePopup,MF_SEPARATOR,0,""
CALL DLL 1,"AppendMenuA",hMenuTempPopup,MF_ENABLED,FILE_DOCUMENT_1,"&Document 1" `submenu item 1
CALL DLL 1,"AppendMenuA",hMenuTempPopup,MF_GRAYED,FILE_DOCUMENT_2,"&Document 2" `submenu item 2
CALL DLL 1,"AppendMenuA",hMenuTempPopup,MF_ENABLED,FILE_DOCUMENT_3,"&Document 3" `submenu item 3
CALL DLL 1,"AppendMenuA",hMenuFilePopup,MF_POPUP,hMenuTempPopup,"&Recent Documents" `Create a submenu inside filemenu
CALL DLL 1,"AppendMenuA",hMenuFilePopup,MF_SEPARATOR,0,""
CALL DLL 1,"AppendMenuA",hMenuFilePopup,MF_ENABLED,FILE_QUIT,"&Quit"
`Create a radio button type menu in File Menu Recents Documents
CALL DLL 1,"CheckMenuRadioItem",hMenuTempPopup,FILE_DOCUMENT_1,FILE_DOCUMENT_3,FILE_DOCUMENT_2,MF_BYCOMMAND
`Create Edit Menu Popup
hMenuEditPopup = CALL DLL(1,"CreatePopupMenu" )
CALL DLL 1,"AppendMenuA",hMenuEditPopup,MF_ENABLED,EDIT_CUT,"&Cut"
CALL DLL 1,"AppendMenuA",hMenuEditPopup,MF_ENABLED,EDIT_COPY,"&Copy"
CALL DLL 1,"AppendMenuA",hMenuEditPopup,MF_ENABLED OR MF_GRAYED,EDIT_PASTE,"&Paste"
`Create Help Menu Popup
hMenuHelpPopup = CALL DLL(1,"CreatePopupMenu" )
CALL DLL 1,"AppendMenuA",hMenuHelpPopup,MF_ENABLED,HELP_ABOUT,"&About"
`Create Options Popup
hOptionsPopup = CALL DLL(1,"CreatePopupMenu" )
CALL DLL 1,"AppendMenuA",hOptionsPopup,MF_ENABLED,OPTION_CUT,"&Cut"
CALL DLL 1,"AppendMenuA",hOptionsPopup,MF_ENABLED,OPTION_COPY,"&Copy"
CALL DLL 1,"AppendMenuA",hOptionsPopup,MF_ENABLED OR MF_GRAYED,OPTION_PASTE,"&Paste"
CALL DLL 1,"AppendMenuA",hOptionsPopup,MF_ENABLED,OPTION_PASTE,"&Select All"
CALL DLL 1,"AppendMenuA",hOptionsPopup,MF_SEPARATOR,0,""
CALL DLL 1,"AppendMenuA",hOptionsPopup,MF_ENABLED,OPTION_UNDO,"&Undo"
CALL DLL 1,"AppendMenuA",hOptionsPopup,MF_GRAYED,OPTION_REDO,"&Redo"
CALL DLL 1,"AppendMenuA",hOptionsPopup,MF_SEPARATOR,0,""
CALL DLL 1,"AppendMenuA",hOptionsPopup,MF_ENABLED,OPTION_CHECKED,"&Checked"
`Check Option menu checked
CALL DLL 1,"CheckMenuItem",hOptionsPopup,OPTION_CHECKED, MF_BYCOMMAND OR MF_CHECKED
`Create Main Menu
hMenu = CALL DLL(1,"CreateMenu" )
CALL DLL 1,"AppendMenuA",hMenu, MF_STRING, FILE, "&File" `Append File to menu
CALL DLL 1,"AppendMenuA",hMenu, MF_STRING, EDIT, "&Edit" `Append Edit to menu
CALL DLL 1,"AppendMenuA",hMenu, MF_STRING, HELP, "&Help" `Append Help to menu
CALL DLL 1,"SetMenu",hWnd,hMenu
SET TEXT SIZE 20
MAKE MEMBLOCK 1,16
MAKE MEMBLOCK 2,8
While Call DLL(1, "GetMessageA", msgPtr, hwnd, 0, 0)
CLS RGB(110,110,110)
tempPtr = msgPtr
msg.hwnd = *tempPtr
inc tempPtr,4
msg.msg = *tempPtr
inc tempPtr,4
msg.wparam =*tempPtr
inc tempPtr,4
msg.lparam =*tempPtr
inc tempPtr,4
msg.time = *tempPtr
inc tempPtr,4
msg.pt.x = *tempPtr
inc tempPtr,4
msg.pt.y = *tempPtr
CALL DLL 1,"GetWindowRect",hWnd,GET MEMBLOCK PTR(1)
menuStartX = MEMBLOCK WORD(1,0) + MENU_ADJUSTMENT_X
menuStartY = MEMBLOCK WORD(1,4) + MENU_ADJUSTMENT_Y
CALL DLL 1,"GetCursorPos",GET MEMBLOCK PTR(2)
cursorX = MEMBLOCK WORD(2,0)
cursorY = MEMBLOCK WORD(2,4)
`Menu Handling
if cursorY > menuStartY AND cursorY < menuStartY + 22
`filemenu
if ( cursorX > menuStartX ) AND ( cursorX < menuStartX + 29 ) AND Msg.msg = 161
CALL DLL 1,"HiliteMenuItem",hWnd,hMenu,FILE, MF_BYCOMMAND OR MF_HILITE
CALL DLL 1,"HiliteMenuItem",hWnd,hMenu,EDIT, MF_BYCOMMAND OR MF_UNHILITE
CALL DLL 1,"HiliteMenuItem",hWnd,hMenu,HELP, MF_BYCOMMAND OR MF_UNHILITE
menuId=CALL DLL(1,"TrackPopupMenu",hMenuFilePopup,TPM_VERPOSANIMATION OR TPM_RETURNCMD,menuStartX,menuStartY + 22,0,hwnd,0)
endif
`Edit menu
if ( cursorX > menuStartX + 28 ) AND ( cursorX < menuStartX + 59 ) AND Msg.msg = 161
CALL DLL 1,"HiliteMenuItem",hWnd,hMenu,EDIT, MF_BYCOMMAND OR MF_HILITE
CALL DLL 1,"HiliteMenuItem",hWnd,hMenu,FILE, MF_BYCOMMAND OR MF_UNHILITE
CALL DLL 1,"HiliteMenuItem",hWnd,hMenu,HELP, MF_BYCOMMAND OR MF_UNHILITE
menuId=CALL DLL(1,"TrackPopupMenu",hMenuEditPopup,TPM_VERPOSANIMATION OR TPM_RETURNCMD,menuStartX + 28,menuStartY + 22 ,0,hwnd,0)
endif
`Help menu
if ( cursorX > menuStartX + 58 ) AND ( cursorX < menuStartX + 155 ) AND Msg.msg = 161
CALL DLL 1,"HiliteMenuItem",hWnd,hMenu,HELP, MF_BYCOMMAND OR MF_HILITE
CALL DLL 1,"HiliteMenuItem",hWnd,hMenu,FILE, MF_BYCOMMAND OR MF_UNHILITE
CALL DLL 1,"HiliteMenuItem",hWnd,hMenu,EDIT, MF_BYCOMMAND OR MF_UNHILITE
menuId=CALL DLL(1,"TrackPopupMenu",hMenuHelpPopup,TPM_VERPOSANIMATION OR TPM_RETURNCMD,menuStartX + 58,menuStartY + 22,0,hwnd,0)
endif
endif
` Clear Menu Hightlight
if MOUSECLICK() > 0
CALL DLL 1,"HiliteMenuItem",hWnd,hMenu,FILE, MF_BYCOMMAND OR MF_UNHILITE
CALL DLL 1,"HiliteMenuItem",hWnd,hMenu,EDIT, MF_BYCOMMAND OR MF_UNHILITE
CALL DLL 1,"HiliteMenuItem",hWnd,hMenu,HELP, MF_BYCOMMAND OR MF_UNHILITE
endif
`Handle right key popup menu
if MOUSECLICK()=2 AND cursorY > 321
menuId=CALL DLL(1,"TrackPopupMenu",hOptionsPopup,TPM_VERPOSANIMATION OR TPM_RETURNCMD,cursorX,cursorY,0,hwnd,0)
endif
` Sample Processing of Menu Commands
if menuId = FILE_DOCUMENT_1
CALL DLL 1,"EnableMenuItem",hMenuFilePopup,FILE_DOCUMENT_1, MF_BYCOMMAND OR MF_GRAYED
CALL DLL 1,"EnableMenuItem",hMenuFilePopup,FILE_DOCUMENT_2, MF_BYCOMMAND OR MF_ENABLED
CALL DLL 1,"EnableMenuItem",hMenuFilePopup,FILE_DOCUMENT_3, MF_BYCOMMAND OR MF_ENABLED
CALL DLL 1,"CheckMenuRadioItem",hMenuTempPopup,FILE_DOCUMENT_1,FILE_DOCUMENT_3,FILE_DOCUMENT_1,MF_BYCOMMAND
endif
if menuId = FILE_DOCUMENT_2
CALL DLL 1,"EnableMenuItem",hMenuFilePopup,FILE_DOCUMENT_2, MF_BYCOMMAND OR MF_GRAYED
CALL DLL 1,"EnableMenuItem",hMenuFilePopup,FILE_DOCUMENT_1, MF_BYCOMMAND OR MF_ENABLED
CALL DLL 1,"EnableMenuItem",hMenuFilePopup,FILE_DOCUMENT_3, MF_BYCOMMAND OR MF_ENABLED
CALL DLL 1,"CheckMenuRadioItem",hMenuTempPopup,FILE_DOCUMENT_1,FILE_DOCUMENT_3,FILE_DOCUMENT_2,MF_BYCOMMAND
endif
if menuId = FILE_DOCUMENT_3
CALL DLL 1,"EnableMenuItem",hMenuFilePopup,FILE_DOCUMENT_3, MF_BYCOMMAND OR MF_GRAYED
CALL DLL 1,"EnableMenuItem",hMenuFilePopup,FILE_DOCUMENT_1, MF_BYCOMMAND OR MF_ENABLED
CALL DLL 1,"EnableMenuItem",hMenuFilePopup,FILE_DOCUMENT_2, MF_BYCOMMAND OR MF_ENABLED
CALL DLL 1,"CheckMenuRadioItem",hMenuTempPopup,FILE_DOCUMENT_1,FILE_DOCUMENT_3,FILE_DOCUMENT_3,MF_BYCOMMAND
endif
if menuId = FILE_QUIT
EXIT
endif
`Print mouse,cursor,menuId info
TEXT 0,SCREEN HEIGHT()-20,"Mouse("+STR$( MOUSEX() ) + "," + STR$( MOUSEY() ) + ") Cursor(" + STR$( cursorX ) + "," + STR$( cursorY ) + ") MenuSelectedId = " + STR$( menuId )
SYNC
Call DLL 1, "TranslateMessage", msgPtr
Call DLL 1, "DispatchMessageA", msgPtr
If Spacekey() = 1 Then Exit
EndWhile
`Distruction
CALL DLL 1,"DestroyMenu",hMenu
CALL DLL 1,"DestroyMenu",hOptionsPopup
DELETE DLL 1
DELETE MEMBLOCK 1
DELETE MEMBLOCK 2
"Computers are useless they can only give you answers."