You can quickly try this code by pasting it into your LB IDE and running it. The menu that popsup when you right-click in the graphicbox should be a list of all the folders in the LB distribution.
A better test would be to put it in a folder of its own and create subfolders with the names you want to appear on the menu.
This is just one way of making popup menus with the Windows API #user32 dlls. The advantages over the LB popupmenu command are:
If the users changes his mind (I say "his" because women don't do this!) and clicks somewhere else, then the old menu disappears and a new one appears. With the LB command the user has to click one more time.
The main advantage is you can load menus dynamically as they are not "hard coded". So your menus can change to reflect the current state of affairs while the program is running.
' program demonstrating API popupmenus - Grahame King Oct 2006'Based on an idea from Sean Brown' Released to public domain - September 27th 2006dim fi$(10,10)
FolderDir$ = DefaultDir$
open "API popups demo"for graphics as #main
#main "trapclose quit.main"
struct popupPoint, x aslong, y aslongglobal popupItems ' number of items in menucall GetItemsToPopup
#main "when rightButtonUp PopsUpMenu"
wait
endsub quit.main handle$
close #handle$
endendsubsub AddMenuItem hndle,MenuRetCode,flag,MenuString$
if flag=0then flag=_MF_STRING
calldll #user32,"AppendMenuA",_
hndle asulong,_
flag aslong,_
MenuRetCode aslong,_
MenuString$ as ptr,_
r aslong' return unusedendsubsub GetItemsToPopup
files FolderDir$, fi$()
numFiles =val(fi$(0,0))
numFolders =val(fi$(0,1))' redim and load array
popupItems = numFolders
redim popupArray$(popupItems)
popupArray$(0)="Folders:}folderMenu"' header}name of popupfor i =1to popupItems
popupArray$(i)= fi$(i+numFiles,1)next i
sort popupArray$(), 1 , popupItems
endsubsub PopsUpMenu Handle$,x,y
' actually pops up menu in popupArray$() at point x,y in window or control, #Handle$' and converts response to action
calldll #user32,"CreatePopupMenu",hpopup asulong
heading$ = word$(popupArray$(0),1,"}")if heading$<>"}"thencall AddMenuItem hpopup,0,_MF_DISABLED,heading$
call AddMenuItem hpopup,0,_MF_SEPARATOR,""endif
flag =0for i =1to popupItems
call AddMenuItem hpopup,i,flag,popupArray$(i)next i
hWnd = hwnd(#Handle$)
popupPoint.x.struct= x
popupPoint.y.struct= y
calldll #user32, "ClientToScreen",_
hWnd aslong,_ ' handle of control or window
popupPoint as struct,_ 'name of struct containing client/screen coorinates
r aslong
tempx = popupPoint.x.struct
tempy = popupPoint.y.struct
flags = _TPM_TOPALIGN OR _TPM_LEFTALIGN OR _TPM_RETURNCMD
CallDLL #user32, "TrackPopupMenu",_
hpopup asuLong,_
flags AsLong,_
tempx AsLong,_
tempy AsLong,_
0AsLong,_
hWnd asuLong,_
0AsLong,_
re aslong' user's selection (because _TPM_RETURNCMD flag set)
calldll #user32,"DestroyMenu",hpopup aslong'take action on user's selection
popupID$ = word$(popupArray$(0),2,"}")selectcase popupID$
case"folderMenu"if re<>0then
notice "You selected "+popupArray$(re);resp$
elseendif' other menus if you have them could go here' but you would have to have a way to introduce the menu into popupArraycase"otherMenu"caseelseendselectendsub
A better test would be to put it in a folder of its own and create subfolders with the names you want to appear on the menu.
This is just one way of making popup menus with the Windows API #user32 dlls. The advantages over the LB popupmenu command are:
If the users changes his mind (I say "his" because women don't do this!) and clicks somewhere else, then the old menu disappears and a new one appears. With the LB command the user has to click one more time.
The main advantage is you can load menus dynamically as they are not "hard coded". So your menus can change to reflect the current state of affairs while the program is running.