Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ShowMenu: check / uncheck menu item
#1
Sorry, this problem is difficult to explain for me.
I hope the code makes it clear enough to explain what I want.

Is it possible to uncheck a menu item rendered with "ShowMenu".
In other words, is it possible to toggle it's checked/unchecked state?
The menu is rendered when the systray icon is right clicked, the whole macro consists of 2 functions
One function is the dialog code which renders an invisible dialog and that dialog code calles the below code under 'MENU CODE'

I have the following code below (under 'MENU CODE') in which the menu item "&Disable hotspot" starts in a checked state.
I want to toggle it's state as soon it is clicked, this I tried to do in the part under "if(i=551)"
But it does not work because of "int hm=GetMenu(dlg_id)" the container "dlg_id" should be "hDlg"
But because the function below is accessed like this:
Function xy_applauncher_dlg
Code:
Copy      Help
Tray- t.AddIcon(":97" "xy_applauncher" 0 &xy_applauncher_systray)

I had to make the dialog ID thread global so that the below function could access it.


MENU CODE


Function xy_applauncher_systray
Code:
Copy      Help
function Tray&tray msg

int- dlg_id
sel msg
,case WM_RBUTTONUP
,,str- default_profile_path_sectioncontent
,,POINT p
,,int px(xm) py(ym)
,,p.x=px
,,p.y=py

,,str md=
,,;BEGIN MENU
,,;&Disable hotspot :551 0 8
,,;&Exit :550
,,;END MENU

,,;; Can add more icons!
,,str s3=
,,;:101 f:\_icons\_systray_test\close.ico
,,
,,SetThreadMenuIcons "550=0" s3

,,int i=ShowMenu(md 0 p)
,,if(i=550)
,,,out
,,,out "EXIT icon clicked (X)"
,,if(i=551)    
,,,out
,,,out "'Disable hotspot' clicked"
,,,int hm=GetMenu(dlg_id) ;; => ? WHAT "DIALOG" ID TO USE, TO ACCESS THE RENDERED MENU DEFINED IN 'md' ?
,,,_i=GetMenuState(hm 551 0)&MFS_CHECKED
,,,out F"The retrieved state of the 'Disable hotspot' menu item: {_i}" ;; RETRIEVING THE STATE ALSO DOES NOT WORK CORRECTLY
,,,if(_i=8)
,,,,CheckMenuItem hm 551 MF_UNCHECKED
,,,else
,,,,CheckMenuItem hm 551 MF_CHECKED


From the microsoft site:
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx

GetMenu does not work on floating menu bars. Floating menu bars are custom controls that mimic standard menus; they are not menus. To get the handle on a floating menu bar, use the Active Accessibility APIs.

Is it even possible?

Other applications for example MalwareBytes have an systray icon in which you can check/uncheck the right click menu items.
(but malwarebytes is a totally different program, programmed in a totally different environment. I just used is an example)

Other example:
[Image: OutlookMinimize.png?resize=275%2C237]
#2
Macro Macro2550
Code:
Copy      Help
str md=
;BEGIN MENU
;&Disable hotspot :551 0 8
;&Exit :550
;END MENU

MenuPopup m.Create(md)

rep
,sel m.Show
,,case 550 break
,,
,,case 551
,,;m.CheckItems( ;;there is no 'uncheck' option
,,_i=GetMenuState(m 551 0)&MFS_CHECKED
,,if _i
,,,CheckMenuItem m 551 0
,,else
,,,CheckMenuItem m 551 MFS_CHECKED

;info: function ShowMenu uses class MenuPopup.

Or use a variable.
Macro Macro2548
Code:
Copy      Help
str md=
;BEGIN MENU
;&Disable hotspot :551 0 0
;&Exit :550
;END MENU

int hotspotDisabled=1
rep
,MenuPopup m.Create(md)
,if(hotspotDisabled) m.CheckItems("551")
,sel m.Show
,,case 550 break
,,
,,case 551
,,hotspotDisabled^1
#3
YES!
Thank you for this!


Forum Jump:


Users browsing this thread: 1 Guest(s)