November 25, 2020, 07:34:41 AM

Author Topic: [bb] Advance Popup Menu extras by gman [ 1+ years ago ]  (Read 679 times)

Offline BlitzBot

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

Description : adds the following functions to the <a href="codearcs6423.html?code=697" >Advance PopupMenu[/url] by Ed From Mars:

GetPopupMenuText$(menu_id%) - returns the text of a menu item based on its assigned ID.

FindPopupHandle%(menu_id%) - returns the handle of a menu item based on its assigned ID.

SetPopupDataItem(item$,value$,ppmenu%) - sets a KEY=VALUE format string that can later be used after an item has been selected.  this can be called multiple times with different KEY=VALUE pairs.  they are seperated using the | character.

GetPopupDataItem$(item$,ppmenu%) - gets a value from the data section that was previously set by SetPopupDataItem().

ClearMenu() - clears out the POPUP_MENU collection.

** NOTES **
- the user32.decls file i use has api_ preceding all the function names.  if yours does not have this, you will get a compile error.  you will need to change all functions that begin with api_ to match the corrosponding function in your .decls file.

** REQUIREMENTS **
- the GetPopupDataItem() and SetPopupDataItem() functions make use of <a href="codearcs3ca0.html?code=290" >gettok$(word$,token,seperator)[/url] by skn3[ac].
- user32.decls file with the following functions defined (note my function calls are preceded by api_ ):
  - CreatePopupMenu
  - ModifyMenu
  - AppendMenu
  - DestroyMenu
  - TrackPopupMenuEx
  - SetForegroundWindow
  - PostMessage

** MODIFICATIIONS **
- the GetPopupDataItem() and SetPopupDataItem() functions make use of a new mndata$ field added to the POPUP_MENU type.  i also added defaulting of this new field in the PopupMenu() function.

Code: [Select]
Type POPUP_MENU
Field txt$ = ""
Field flag
Field menu_id = 0
Field popup.POPUP_MENU = Null
Field parent.POPUP_MENU = Null
Field root =  0
Field mndata$="" ; 2004_08_10 (gman) - added string to hold extra data
End Type

; 2004_08_10 (gman) -  added passing and setting of new mndata value
Function PopupMenu%(txt$="",menu_id=0,parent=0,mndata$="")
Local pm.POPUP_MENU=New POPUP_MENU
Local p.POPUP_MENU=Object.POPUP_MENU(parent)
If p=Null
;root
pmpopup=pm
pmparent=Null
Else
;link parent to root of new popupmenu
If ppopup=Null
ppopup=New POPUP_MENU
ppopupparent=Null
EndIf
;node
pm xt=txt
pmmenu_id=menu_id
pmparent=ppopup
pmmndata=mndata    ; 2004_08_10 (gman) - set the new mndata field
EndIf

Local ppmenu=Handle(pm)
Return ppmenu
End Function


- updated ShowPopupMenu to take X,Y as a parameter.  they default to the original MouseX(),MouseY() if not passed.
- updated ShowPopupMenu to take a new lTray parameter and added corrosponding tray popup code.  this is False by default, make True if using the popup from a tray icon.  this is a fix as detailed in MSKB <a href="http://support.microsoft.com/support/kb/articles/q135/7/88.asp" target="_blank">Q135788[/url].

Code: [Select]
; ================================
; Show popupmenu at mouse position
; changes:
; - 2004_08_10 (gman) - added X,Y positioning capabilities
; - 2004_08_17 (gman) - added new tray parameter and called functions as described in MSKB Q135788
; (http://support.microsoft.com/support/kb/articles/q135/7/88.asp)
; ================================

Function ShowPopupMenu%(ppmenu,win=0,nX=0,nY=0,lTray=False)
Local TPM_RETURNCMD = $100
Local pm.POPUP_MENU=Object.POPUP_MENU(ppmenu)
Local hmenu=pmoot

If win=0 Then win=ActiveWindow()

; 2004_08_10 (gman) - if X,Y not passed, default to MouseX,MouseY
If nX=0 Then nX=MouseX()
If nY=0 Then nY=MouseY()

If lTray Then api_SetForegroundWindow(QueryObject(win,1)) ; 2004_08_17 (gman) - fix for tray menus per Q135788

Local menu_id=api_TrackPopupMenuEx(hmenu,TPM_RETURNCMD,nX,nY,QueryObject(win,1),0)

If lTray Then api_PostMessage(QueryObject(win,1),$0000,0,0) ; 2004_08_17 (gman) - fix for tray menus per Q135788

Return menu_id
End Function


Code :
Code: BlitzBasic
  1. ; ================================
  2. ; Author: gman
  3. ; Date: 2004_08_10
  4. ; Title: FindPopupHandle
  5. ; Description:  - addon For the Advance PopupMenu by Ed From Mars (ID: 697)
  6. ;                       - gets the popupmenu Handle based on menu_id
  7. ;
  8. ; Requirements: - stock Advance PopupMenu
  9. ; ================================
  10. Function FindPopupHandle(menu_id%)
  11.         Local pm_find.POPUP_MENU
  12.        
  13.         For pm_find=Each POPUP_MENU
  14.                 If pm_findmenu_id=menu_id
  15.                         Return Handle(pm_find)
  16.                 EndIf
  17.         Next
  18.         RuntimeError "Invalid menu_id passed to FindPopupHandle !"
  19. End Function
  20.  
  21. ; ================================
  22. ; Author: gman
  23. ; Date: 2004_08_10
  24. ; Title: GetPopupMenuText
  25. ; Description:  - addon For the Advance PopupMenu by Ed From Mars (ID: 697)
  26. ;                       - gets the text of a popupmenu based on its menu_id
  27. ;
  28. ; Requirements: - stock Advance PopupMenu
  29. ;                       - FindPopupHandle by gman
  30. ; ================================
  31. Function GetPopupMenuText$(menu_id%)
  32.         ; get the popup based on menu_id.  will fail during find if menu_id doesnt exist.
  33.         Local pm.POPUP_MENU=Object.POPUP_MENU(FindPopupHandle(menu_id))
  34.        
  35.         If pmparent=Null Then RuntimeError "GetPopupMenuText does not work with popupmenu root !"
  36.                
  37.         Return pm       xt$
  38. End Function
  39.  
  40. ; ================================
  41. ; Author: gman
  42. ; Date: 2004_08_10
  43. ; Title: SetPopupDataItem
  44. ; Description:  - addon for the Advance PopupMenu by Ed From Mars (ID: 697)
  45. ;                       - sets a value in the mndata$ field
  46. ;
  47. ; Requirements: - Advance PopupMenu, modified to have a mndata$ field in the POPUP_MENU type
  48. ;                       - gettok function by skn3[ac] (ID: 290)
  49. ;                       - GetPopupDataItem function by gman
  50. ; ================================
  51. Function SetPopupDataItem(item$,value$,ppmenu)
  52.  
  53.         Local pm.POPUP_MENU=Object.POPUP_MENU(ppmenu)
  54.         If (Handle(pm)<=0) Then RuntimeError "Invalid handle passed to SetPopupDataItem !"
  55.  
  56.         item$=Upper(item$)
  57.  
  58.         If (item$="") Then RuntimeError "Empty item passed to SetPopupDataItem !"
  59.  
  60.         Local curval$=GetPopupDataItem(item$,ppmenu)
  61.  
  62.         If (Instr(pmmndata$,"|"+item$+"=")=0)
  63.                 pmmndata$=pmmndata$+"|"+item$+"="+value$
  64.         Else
  65.                 pmmndata$=Replace(pmmndata$,"|"+item$+"="+curval$,"|"+item$+"="+value$)
  66.         EndIf
  67.  
  68. End Function
  69.  
  70. ; ================================
  71. ; Author: gman
  72. ; Date: 2004_08_10
  73. ; Title: GetPopupDataItem
  74. ; Description:  - addon for the Advance PopupMenu by Ed From Mars (ID: 697)
  75. ;                       - gets a value from the mndata$ field
  76. ;
  77. ; Requirements: - Advance PopupMenu, modified to have a mndata$ field in the POPUP_MENU type
  78. ;                       - gettok function by skn3[ac] (ID: 290)
  79. ; ================================
  80. Function GetPopupDataItem$(item$,ppmenu)
  81.         Local pm.POPUP_MENU=Object.POPUP_MENU(ppmenu)
  82.         If (Handle(pm)<=0) Then RuntimeError "Invalid handle passed to GetPopupDataItem !"
  83.  
  84.         item$=Upper(item$)
  85.  
  86.         If (item$="") Then RuntimeError "Empty item passed to GetPopupDataItem !"
  87.  
  88.         Local nCnt=0
  89.         Local temp$=""
  90.        
  91.         Repeat
  92.                 nCnt=nCnt+1
  93.                 temp$=gettok(pmmndata$,nCnt,"|")
  94.                 If gettok(temp$,1,"=")=item$ Then Return gettok(temp$,2,"=")
  95.         Until (temp$="")
  96.  
  97.         Return ""
  98. End Function
  99.  
  100. ; ================================
  101. ; Author: gman
  102. ; Date: 2004_11_12
  103. ; Title: ClearMenu
  104. ; Description:  - addon for the Advance PopupMenu by Ed From Mars (ID: 697)
  105. ;                               - clears out the POPUP_MENU list
  106. ;                               - this is a must if you are building dynamic menus that rebuild each time
  107. ;
  108. ; Requirements: - Advance PopupMenu
  109. ; ================================
  110. Function ClearMenu()
  111.         Delete Each POPUP_MENU
  112. End Function


Comments :


gman(Posted 1+ years ago)

 changes for SetPopupDataItem:- fixed replace not storing back to mndata$- changed to better handle setting an existing value to empty


gman(Posted 1+ years ago)

 changes for ShowPopupMenu:- changed to take a new lTray parameter and added corrosponding tray popup code. this is False by default, make True if using the popup from a tray icon. this is a fix as detailed in MSKB <a href="http://support.microsoft.com/support/kb/articles/q135/7/88.asp" target="_blank">Q135788[/url].


gman(Posted 1+ years ago)

 - added ClearMenu().  if you dynamically add menu items potentially each time the menu is shown , this is a must.  call it after you process the current menu event.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal