Code archives/BlitzPlus Gui/Popupmenus!
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
| THIS CODE WAS UPDATED AS OF BLITZPLUS 1.34 - No need for GetCursor. MouseX(),MouseY() takes care of that. - Had to change the FindWindow class to "BLITZMAX_WINDOW_CLASS" This app uses a userlib to refer to the user32.dll library and get some popupmenu commands! Make sure you add the code at the top (in comments) to a "user32.decls" file and put it in your blitzplus\userlibs directory... | |||||
; .lib "user32.dll"
; FindWindow$ ( hwnd ):"FindWindowA"
; GetMenu%( hnd )
; GetSubMenu%( hnd,npos )
; TrackPopupMenuEx%( mnu,flags,x,y,hwnd,tpm )
Const TPM_RETURNCMD = $100
;Create window
win = CreateWindow("Popupmenu Test",100,100,400,300)
txt = CreateLabel("Right-click anywhere to open popupmenu",10,10,250,50,win)
mnuFile = CreateMenu("&File",0,WindowMenu(win))
mnuFileOpen = CreateMenu("&Open",1,mnuFile)
mnuFileOpen = CreateMenu("&Save",1,mnuFile)
mnuFileOpen = CreateMenu("&Exit",1,mnuFile)
mnuEdit = CreateMenu("&Edit",0,WindowMenu(win))
mnuEditCut = CreateMenu("&Cut", 1,mnuEdit)
mnuEditCopy = CreateMenu("&Copy", 2,mnuEdit)
mnuEditPaste = CreateMenu("&Paste",3,mnuEdit)
mnuEditMore = CreateMenu("More", 4,mnuEdit)
mnuEditMoreStuff = CreateMenu("Stuff",5,mnuEditMore)
UpdateWindowMenu(win)
;Find handle for "Edit" submenu
hwnd = FindWindow("BLITZMAX_WINDOW_CLASS","Popupmenu Test")
hmnu = GetSubMenu(GetMenu(hwnd),1) ;0 = File, 1 = Edit, etc...
Repeat
If WaitEvent(1)=$803 Or KeyHit(1) Then End
If MouseHit(2) Then
index = TrackPopupMenuEx (hmnu,TPM_RETURNCMD,MouseX(),MouseY(),hwnd,0)
SetGadgetText txt,"You clicked item : " + index
End If
Forever |
Comments
| ||
| This doesn't work... |
| ||
| I dont know "user32.dll" but i guess you should add lib ref as : FindWindow$ ( <win app name>, hwnd :"FindWindowA" instead of : FindWindow$ ( hwnd ):"FindWindowA" since you call this command in your code as : FindWindow("BLITZMAX_WINDOW_CLASS","Popupmenu Test") |
| ||
| By the way i tried adding an argument but it return 0. Is that that "BLITZMAX_WINDOW_CLASS" or is that im using a wrong argument vars type (class$,class% or class#...)? |
| ||
| 6 years old. I suggest you go to MSDN. |
Code Archives Forum