Ooops
November 25, 2020, 08:19:44 AM

Author Topic: [bb] Advance PopupMenu by Red [ 1+ years ago ]  (Read 713 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Advance PopupMenu by Red [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Advance PopupMenu
Author : Red
Posted : 1+ years ago

Description : [Blitz v1.34]
It works like B+ createmenu functions...
You could append popupmenus between them.
[a http://www.blitz3dfr.com/click/clic.php?url=http://perso.wanadoo.fr/eddy.dev/projet/Popup_Menu.rar]Download the example files[/a]
Bug fixed : AppendPopupMenu, SetPopupMenuState, modify state [May 22 2003]
;********************************
Userlib file :  /userlibs/user32.decls
;********************************
Code: [Select]
.lib "user32.dll"
TrackPopupMenuEx%( mnu,flags,x,y,hwnd,tpm )
CreatePopupMenu%()
AppendMenu%(mnu,flags,menuID,txt$):"AppendMenuA"
ModifyMenu%(mnu,pos,flags,menuID,txt$):"ModifyMenuA"
DestroyMenu%(mnu)

Code example :
Code: [Select]
;create window
Global WIN = CreateWindow("Easy PopupMenu",200,200,400,100,0,1)

;create popupmenu
Global POPUP = PopupMenu()
PopupMenu("checked",1,POPUP)
PopupMenu("grayed+disabled",2,POPUP)
PopupMenu("change text",3,POPUP)
PopupMenu("",0,POPUP)
item = PopupMenu("item test",4,POPUP)
UpdatePopupMenu POPUP

Global POPUP2 = PopupMenu()
PopupMenu("See Alpha...",10,POPUP2)
PopupMenu("See Numeric...",20,POPUP2)
PopupMenu("See nothing...",30,POPUP2)
item2 = PopupMenu("MORE ITEMS HERE",40,POPUP2)
UpdatePopupMenu POPUP2

Global POPUP3 = PopupMenu()
PopupMenu("A",101,POPUP3)
PopupMenu("B",102,POPUP3)
PopupMenu("C",103,POPUP3)
UpdatePopupMenu POPUP3

Global POPUP4 = PopupMenu()
PopupMenu("1",601,POPUP4)
PopupMenu("2",602,POPUP4)
item3 = PopupMenu("3",603,POPUP4)
UpdatePopupMenu POPUP4

ModifyPopupMenuState(item3,1)

;mainloop
Repeat
;Launch PopupMenu left click
If MouseHit(1)
menu_id=ShowPopupMenu(POPUP2,WIN)
If menu_id=10 Then AppendPopupMenu(item2,POPUP3)
If menu_id=20 Then AppendPopupMenu(item2,POPUP4)
If menu_id=30
detached_menu = DetachSubMenu(item2)
If detached_menu=POPUP3 Notify "you've detached POPUP 3 :)"
EndIf
SetStatusText WIN,"menuID="+menu_id
EndIf

;Launch PopupMenu right click
If MouseHit(2)
menu_id=ShowPopupMenu(POPUP,WIN)
If menu_id=1 Then ModifyPopupMenuState(item,1);checked
If menu_id=2 Then ModifyPopupMenuState(item,2);grayed+disabled
If menu_id=3 Then ModifyPopupMenuText(item,"text changed")
SetStatusText WIN,"menuID="+menu_id
EndIf

;Exit
If WaitEvent()=$803 Then End
Forever

Blitz functions : [/i]

Code :
Code: BlitzBasic
  1. ; ================================
  2. ; Load popupmenu
  3. ; ================================
  4. Type POPUP_MENU
  5.         Field txt$ = ""
  6.         Field flag
  7.         Field menu_id = 0
  8.         Field popup.POPUP_MENU = Null  
  9.         Field parent.POPUP_MENU = Null
  10.         Field root =  0
  11. End Type
  12.  
  13. Function PopupMenu%(txt$="",menu_id=0,parent=0)
  14.         Local pm.POPUP_MENU=New POPUP_MENU
  15.         Local p.POPUP_MENU=Object.POPUP_MENU(parent)
  16.         If p=Null
  17.                 ;root
  18.                 pmpopup=pm
  19.                 pmparent=Null          
  20.         Else           
  21.                 ;link parent to root of new popupmenu
  22.                 If ppopup=Null
  23.                         ppopup=New POPUP_MENU
  24.                         ppopupparent=Null                              
  25.                 EndIf
  26.                 ;node
  27.                 pm      xt=txt 
  28.                 pmmenu_id=menu_id      
  29.                 pmparent=ppopup
  30.         EndIf
  31.        
  32.         Local ppmenu=Handle(pm)
  33.         Return ppmenu
  34. End Function
  35.  
  36. ; ================================
  37. ; Create popupmenu
  38. ; ================================
  39.  
  40. Function UpdatePopupMenu(ppmenu)       
  41.         Local MF_STRING = $0
  42.         Local MF_SEPARATOR = $800
  43.         Local MF_POPUP = $10
  44.        
  45.         Local MF_DISABLED=$02
  46.         Local MF_GRAYED=$01
  47.         Local MF_CHECKED=$08   
  48.        
  49.         Local hmenu
  50.         Local pmRoot.POPUP_MENU=Object.POPUP_MENU(ppmenu)
  51.         Local pm.POPUP_MENU    
  52.         Local submenu.POPUP_MENU       
  53.  
  54.         If pmRootparent<>Null RuntimeError "UpdatePopupMenu works only with popupmenu root !"
  55.        
  56.         ;create root
  57.         pmRoot
  58. oot=CreatePopupMenu()                  
  59.        
  60.         ;create menu items
  61.         For pm=Each POPUP_MENU
  62.  
  63.                 If pmparent=pmRoot                                             
  64.                         ;state of item 
  65.                         pmflag=pmflag And (MF_CHECKED Or MF_GRAYED Or MF_DISABLED)
  66.                         If pm   xt=""
  67.                                 pmflag=pmflag Or MF_SEPARATOR          
  68.                         Else
  69.                                 pmflag=pmflag Or MF_STRING
  70.                         EndIf
  71.                         If pmpopup<>Null
  72.                                 ;create submenu
  73.                                 submenu=pmpopup
  74.                                 UpdatePopupMenu Handle(submenu)                                                                        
  75.                                 ;link to menu item
  76.                                 pmflag=pmflag Or MF_POPUP And ~MF_SEPARATOR
  77.                                 pmmenu_id=submenu
  78. oot
  79.                         EndIf
  80.  
  81.                         ;create item
  82.                         hmenu=pmparent
  83. oot
  84.                         AppendMenu hmenu,pmflag,pmmenu_id,pm    xt$
  85.                 EndIf
  86.         Next    
  87. End Function
  88.  
  89. ; ================================
  90. ; Append a popupmenu
  91. ; ================================
  92.  
  93. Function AppendPopupMenu(ppmenu,ppmenuToAppend)
  94.         Local MF_BYPOSITION = $400
  95.        
  96.         Local MF_STRING = $0
  97.         Local MF_POPUP = $10
  98.        
  99.         Local hmenu
  100.         Local pm.POPUP_MENU=Object.POPUP_MENU(ppmenu)
  101.         Local pmA.POPUP_MENU=Object.POPUP_MENU(ppmenuToAppend)
  102.         Local pm_.POPUP_MENU
  103.        
  104.         If pm=Null Or pmA=Null
  105.                 RuntimeError "A parameter misses in AppendPopupMenu Call..."
  106.         EndIf
  107.         If pmparent=Null And pmApopupparent<>Null  
  108.                 RuntimeError "AppendPopupMenu needs a popupmenu item and a popupmenu root !"
  109.         EndIf
  110.  
  111.  
  112.         ;broke last link
  113.         DetachSubMenu ppmenu
  114.        
  115.         ;link
  116.         For pm_=Each POPUP_MENU
  117.                 If pm_=pm
  118.                         Exit
  119.                 Else
  120.                         If pm_parent=pmparent Then pos=pos+1
  121.                 EndIf
  122.         Next
  123.         pmflag=MF_STRING Or MF_POPUP Or MF_BYPOSITION  
  124.         pmpopup=pmA
  125.        
  126.         ;update item   
  127.         hmenu=pmparent
  128. oot
  129.         ModifyMenu hmenu,pos,pmflag,pmpopup
  130. oot,pm  xt     
  131.  
  132. End Function
  133.  
  134. ; ================================
  135. ; Detach a submenu
  136. ; ================================
  137.  
  138. Function DetachSubMenu%(ppmenu)
  139.         Local MF_STRING = $0
  140.         Local MF_POPUP = $10
  141.         Local MF_BYPOSITION = $400
  142.  
  143.         Local pm_.POPUP_MENU
  144.         Local pm.POPUP_MENU=Object.POPUP_MENU(ppmenu)
  145.         Local pmD.POPUP_MENU
  146.  
  147.         If pmparent=Null Then RuntimeError " DetachPopupMenu : it's a popupmenu root, there's nothing to detach !"
  148.  
  149.         ;link
  150.         For pm_=Each POPUP_MENU
  151.                 If pm_=pm
  152.                         Exit
  153.                 Else
  154.                         If pm_parent=pmparent Then pos=pos+1
  155.                 EndIf
  156.         Next   
  157.         pmD=pmpopup
  158.         pmpopup=Null
  159.         pmflag=MF_STRING Or MF_BYPOSITION      
  160.  
  161.         ;update menu   
  162.         DestroyMenu pmparent
  163. oot
  164.         UpdatePopupMenu Handle(pmparent)
  165.  
  166.         ;recreate submenu      
  167.         If pmD<>Null
  168.                 DestroyMenu pmD
  169. oot
  170.                 UpdatePopupMenu Handle(pmD)
  171.         EndIf
  172.        
  173.         Return Handle(pmD)
  174. End Function
  175.  
  176. ; ================================
  177. ; Modify text
  178. ; ================================
  179.  
  180. Function ModifyPopupMenuText$(ppmenu,txt$)
  181.         Local pm.POPUP_MENU=Object.POPUP_MENU(ppmenu)
  182.  
  183.         If pmparent=Null Then RuntimeError "ModifyPopupMenuText does not work with popupmenu root !"
  184.        
  185.         Local hmenu=pmparent
  186. oot
  187.         Local oldtxt$=pm        xt
  188.         pm      xt=txt
  189.         ModifyMenu hmenu,pmmenu_id,pmflag,pmmenu_id,pm  xt
  190.        
  191.         Return oldtxt$
  192. End Function
  193.  
  194. ; ================================
  195. ; Modify state
  196. ; ================================
  197.  
  198. Function ModifyPopupMenuState(ppmenu,state) ;1=checked ;2=grayed ;4=disabled
  199.         Local MF_DISABLED=$02
  200.         Local MF_GRAYED=$01
  201.         Local MF_CHECKED=$08
  202.         Local pm.POPUP_MENU=Object.POPUP_MENU(ppmenu)
  203.        
  204.         If pmparent=Null Then RuntimeError "ModifyPopupMenuState does not work with popupmenu root !"
  205.  
  206.         pmflag=0
  207.         If (state And $01) Then pmflag=MF_CHECKED
  208.         If (state And $02) Then pmflag=pmflag Or MF_GRAYED
  209.         If (state And $04) Then pmflag=pmflag Or MF_DISABLED
  210.  
  211.         Local hmenu=pmparent
  212. oot
  213.         ModifyMenu hmenu,pmmenu_id,pmflag,pmmenu_id,pm  xt
  214.        
  215. End Function
  216.  
  217. ; ================================
  218. ; Get state
  219. ; ================================
  220.  
  221. Function GetPopupMenuState%(ppmenu)
  222.         Local MF_DISABLED=$02
  223.         Local MF_GRAYED=$01
  224.         Local MF_CHECKED=$08
  225.         Local pm.POPUP_MENU=Object.POPUP_MENU(ppmenu)
  226.        
  227.         If pmparent=Null Then RuntimeError "ModifyPopupMenuState does not work with popupmenu root !"
  228.        
  229.         If (pmflag And MF_CHECKED) Then state=1
  230.         If (pmflag And MF_GRAYED)  Then state=state Or 2
  231.         If (pmflag And MF_DISABLED) Then state=state Or 4
  232.        
  233.         Return state
  234. End Function
  235.  
  236. ; ================================
  237. ; Show popupmenu at mouse position
  238. ; ================================
  239.  
  240. Function ShowPopupMenu%(ppmenu,win=0)
  241.         Local TPM_RETURNCMD = $100
  242.         Local pm.POPUP_MENU=Object.POPUP_MENU(ppmenu)
  243.         Local hmenu=pm
  244. oot
  245.        
  246.         If win=0 Then win=ActiveWindow()
  247.                
  248.         Local menu_id=TrackPopupMenuEx(hmenu,TPM_RETURNCMD,MouseX(),MouseY(),QueryObject(win,1),0)
  249.         Return menu_id 
  250. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal