Older Version Newer Version

GrahameKing GrahameKing Sep 26, 2006 - "pasted in code"

' program demonstrating API popupmenus - Grahame King Oct 2006 global true, false true = (1=1) : false = not(true) dim fi$(10,10) FolderDir$ = DefaultDir$ open "API popups demo" for graphics as #main #main "trapclose quit.main" struct popupPoint, x as long, y as long global popupItems call GetItemsToPopup #main "when rightButtonUp PopsUpMenu" wait end sub quit.main handle$ close #handle$ end end sub sub AddMenuItem hndle,MenuRetCode,flag,MenuString$ if flag = 0 then flag = _MF_STRING calldll #user32,"AppendMenuA",_ hndle as ulong,_ flag as long,_ MenuRetCode as long,_ MenuString$ as ptr,_ r as long ' return unused end sub sub 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 popup for i = 1 to popupItems popupArray$(i) = fi$(i+numFiles,1) next i sort popupArray$(), 1 , popupItems end sub sub 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 as ulong heading$ = word$(popupArray$(0),1,"}") if heading$<>"}" then call AddMenuItem hpopup,0,_MF_DISABLED,heading$ call AddMenuItem hpopup,0,_MF_SEPARATOR,"" end if flag = 0 for i = 1 to 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 as long,_ ' handle of control or window popupPoint as struct,_ 'name of struct containing client/screen coorinates r as long tempx = popupPoint.x.struct tempy = popupPoint.y.struct flags = _TPM_TOPALIGN OR _TPM_LEFTALIGN OR _TPM_RETURNCMD CallDLL #user32, "TrackPopupMenu",_ hpopup as uLong,_ flags As Long,_ tempx As Long,_ tempy As Long,_ 0 As Long,_ hWnd as uLong,_ 0 As Long,_ re as long ' user's selection (because _TPM_RETURNCMD flag set) calldll #user32,"DestroyMenu",hpopup as long 'take action on user's selection popupID$ = word$(popupArray$(0),2,"}") select case popupID$ case "folderMenu" if re<>0 then notice "You selected "+popupArray$(re);resp$ else end if ' other menus if you have them could go here ' but you would have to have a way to introduce the menu into popupArray case "otherMenu" case else end select end sub