Ooops
November 28, 2020, 02:44:07 AM

Author Topic: [bb] Popupmenus! by cyberseth [ 1+ years ago ]  (Read 577 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Popupmenus! by cyberseth [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : Popupmenus!
Author : cyberseth
Posted : 1+ years ago

Description : 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 blitzplususerlibs directory...


Code :
Code: BlitzBasic
  1. ; .lib "user32.dll"
  2. ; FindWindow$ ( hwnd ):"FindWindowA"
  3. ; GetMenu%( hnd )
  4. ; GetSubMenu%( hnd,npos )
  5. ; TrackPopupMenuEx%( mnu,flags,x,y,hwnd,tpm )
  6.  
  7. Const TPM_RETURNCMD =   $100
  8.  
  9. ;Create window
  10. win = CreateWindow("Popupmenu Test",100,100,400,300)
  11. txt = CreateLabel("Right-click anywhere to open popupmenu",10,10,250,50,win)
  12.  
  13. mnuFile = CreateMenu("&File",0,WindowMenu(win))
  14. mnuFileOpen = CreateMenu("&Open",1,mnuFile)
  15. mnuFileOpen = CreateMenu("&Save",1,mnuFile)
  16. mnuFileOpen = CreateMenu("&Exit",1,mnuFile)
  17. mnuEdit = CreateMenu("&Edit",0,WindowMenu(win))
  18. mnuEditCut = CreateMenu("&Cut",    1,mnuEdit)
  19. mnuEditCopy = CreateMenu("&Copy",  2,mnuEdit)
  20. mnuEditPaste = CreateMenu("&Paste",3,mnuEdit)
  21. mnuEditMore = CreateMenu("More",   4,mnuEdit)
  22. mnuEditMoreStuff = CreateMenu("Stuff",5,mnuEditMore)
  23. UpdateWindowMenu(win)
  24.  
  25. ;Find handle for "Edit" submenu
  26. hwnd = FindWindow("BLITZMAX_WINDOW_CLASS","Popupmenu Test")
  27. hmnu = GetSubMenu(GetMenu(hwnd),1) ;0 = File, 1 = Edit, etc...
  28.  
  29. Repeat
  30.         If WaitEvent(1)=$803 Or KeyHit(1) Then End
  31.         If MouseHit(2) Then
  32.                 index = TrackPopupMenuEx (hmnu,TPM_RETURNCMD,MouseX(),MouseY(),hwnd,0)
  33.                 SetGadgetText txt,"You clicked item : " + index
  34.         End If
  35. Forever


Comments :


Phoenix(Posted 1+ years ago)

 This doesn't work...


Zeachco(Posted 1+ years ago)

 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")


Zeachco(Posted 1+ years ago)

 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#...)?


N(Posted 1+ years ago)

 6 years old.  I suggest you go to MSDN.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal