Jump to content

Can I keep a tray menu open after selecting an option?


Recommended Posts

Hi Everyone, I have a standard tray item with multiple submenus with radio options.  Changing any of those submenu radio options closes the entire menu tree.  I'd like users of my script to be able to continue to browse the submenus after picking one, so I'd prefer it didn't close.  Any way I can make this change?

 

Link to comment
Share on other sites

I'm sure there is a way to do it but I wouldn't know how. I don't know of any windows message to register with GUIRegisterMsg because you're talking about the tray menu, which is apart of the notification area. What I think you would have to do is something like this. And you can use

$hSysTray_Handle = ControlGetHandle('[Class:NotifyIconOverflowWindow]', '', '[Class:ToolbarWindow32;Instance:1]')

To get all the icon titles in the overflow notification area. You'll have to intercept when the user clicks on a button in your tray menu, and when right-click it in your code.

Honestly, this seems bad. I'd use a context menu on your GUI instead, much simpler and cleaner.

#include <GUIConstants.au3>
#include <GUIMenu.au3>

Local $hGUI = GUICreate("Example")
Local $hMenu = GUICtrlCreateContextMenu()
Local $idExample1 = GUICtrlCreateMenuItem("Example 1", $hMenu, 0)
Local $idExample2 = GUICtrlCreateMenuItem("Example 2", $hMenu, 1)
Local $idExample3 = GUICtrlCreateMenuItem("Example 3", $hMenu, 2)
Local $aPosition = 0

GUISetState(@SW_SHOW, $hGUI)
GUIRegisterMsg($WM_COMMAND, WM_COMMAND)
GUIRegisterMsg($WM_CONTEXTMENU, WM_CONTEXTMENU)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
            Exit 0
    EndSwitch
WEnd

Func WM_COMMAND($hWndFrom, $iMsg, $wParam, $lParam)
    #forceref $hWndFrom, $iMsg, $wParam
    Local $iIDFrom = BitAND($wParam, 0xFFFF)

    Switch ($hWndFrom)
        Case $hGUI
            If ($iIDFrom <= $idExample3 Or $idExample1 >= $iIDFrom) Then
                If (Not IsArray($aPosition)) Then Return -1
                GUICtrlSetState($iIDFrom, BitXOR(GUICtrlRead($iIDFrom), $GUI_ENABLE, $GUI_UNCHECKED, $GUI_CHECKED))
                _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($hMenu), $hWndFrom, $aPosition[0], $aPosition[1])
            EndIf
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func WM_CONTEXTMENU($hWndFrom, $iMsg, $wParam, $lParam)
    ; Just to track where the menu should be after clicking a button
    $aPosition = MouseGetPos()
EndFunc   ;==>WM_CONTEXTMENU

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...