SadBunny

how to activate systray icon menu for the user?

16 posts in this topic

Hi people!

Haven't been on this forum for ages. Good to be back.

I am writing an autoit script for colleagues who use multiple instances (windows) of a fullscreen sales application. It keeps track of which window is for which agent login, and lists those windows in a systray menu so users can taskswitch more easily. Since it is a fullscreen application I chose to do everything through the systray, to save on screen estate.

The problem: the workstations have many programs running in the system tray and not very high screen resolution, so the system trays are in "hide inactive items" mode. Since the sales system is keyboard-intensive, having to switch hands to the mouse and clicking two times before they even reach the systray menu is somewhat bothersome.

The solution I am looking for: a hotkey in the script that activates the systray menu of the script, so users don't have to peel open the system tray with that "show all icons" arrow before they reach the script tray icon.

Possible alternative solution is to have a hotkey show a (to be made) custom popup window with buttons, but I'd like to keep using the systray.

Oh, and another question: for tray items, it seems I have the choice between either checkbox items or radio control groups for the tray menu items. Not a big problem, I use radio buttons and it works kinda like a regular button, but, why can't they just be regular buttons like in every other application? :unsure:


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites



SadBunny,

This works for me - it shows all the hidden icons and then opens its own menu which you can activate via the keyboard (you said that is what you wanted): ;)

#include <GuiToolBar.au3>

Global $hSysTray_Handle

HotKeySet("q", "_Show")

Opt("TrayMenuMode", 3)

TrayCreateItem("One")
TrayCreateItem("Two")
TrayCreateItem("Three")
TrayCreateItem("")
$mExit_Item = TrayCreateItem("Exit")
TraySetState()
TraySetToolTip("TestScript")

While 1
    If TrayGetMsg() = $mExit_Item Then Exit
WEnd

Func _Show()

    $iSystray_ButtonNumber = Get_Systray_Index("TestScript") ; Put your traytip text here as before
    If @error Then
        MsgBox(16, "Error", "Icon not found in system tray")
        Exit
    EndIf

    $hTaskBarHandle = WinGetHandle("[Class:Shell_TrayWnd]", "")

    ControlClick($hTaskBarHandle, "", "[CLASS:Button; INSTANCE:1]")

    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")

EndFunc   ;==>_Show

Func Get_Systray_Index($sText)

    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf

    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf

    ; Look for  tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sText) > 0 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return SetError(1, 0, -1) ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc   ;==>Get_Systray_Index

I used the "q" HotKey to display the menu and set the tooltip to a pretty generic value - you can obviously change these to match your required values. It works nicely for me on Vista x32 when I set the Systray status to "Hide" for the exe. Does it for you? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the fast and useful reply!

It works pretty charmingly, except for one thing: after 'q' activates the menu, the mouse pointer disappears when mousing over the activated menu. Since I was looking for a keyboard-based solution anyway, it's probably not a biggie, but still, GUI-wise it looks&feels weird. Know anything about that?

/edit: by the way, I am devving on a W7 x64 box here. Script will be used on XP x32. This GUI issue might be a windows quirk?

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

SadBunny,

Glad it works for you too. :)

The mouse cursor is always visible for me over the activated menu, so I cannot really suggest anything about that - sorry. :wacko:

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks a bunch anyway, your solution is very usable! And I learned something about directly interacting with windows system controls. Sweet! :huggles:


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

This is bit old, but ill bump it instead of opening another thread. 

Running M23's example straightforward returns Icon not found in system tray

OS win7 x64 & Autoit 3.3.10.2. 

The program runs smoothly, there is an icon in the tray and the menu on the icon is correct

What can be wrong, since i don't understand this script (yet) 

Share this post


Link to post
Share on other sites

JustSomeone,

I have just tested the above code on my Win7 x32 machine and it works, so I cannot suggest why it does not work for you. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

JustSomeone,

I have just tested the above code on my Win7 x32 machine and it works, so I cannot suggest why it does not work for you. :(

M23

It works, if the icon is shown, hoever if the icon is hidden (in that box that windows keep its icons) it does not work.

Help please

Share this post


Link to post
Share on other sites

JustSomeone,

I have spent the past few hours trying to find out how to access the hidden icons - alas without success. The change in Win 7 to the popup box has changed the whole systray model. :(

But I will keep looking. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

For me it works (at least at the systray box, not fully clear which box / classname you need for the popup one it seems to be nested)

I was able to get the missing icon error but that is due to not changing this line

$iSystray_ButtonNumber = Get_Systray_Index("TestScript") ; Put your traytip text here as before 

>Running:(3.3.12.0):C:Program Files (x86)AutoIt3autoit3.exe
win7 64 bits

But class is differently
Title is: <NotificationOverflow> Class := <NotifyIconOverflowWindow>
*** Parent Information ***
Title is: <Bureaublad> Class := <#32769>

so you have to tweak with this
 

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

Share this post


Link to post
Share on other sites

junkew,

Thanks for the hints - got it working now. :thumbsup:


JustSomeone,

This script looks first in the main systray - if it does not find the icon it opens the popup and looks there:

#include <GuiToolBar.au3>

Global $hSysTray_Handle
Global $sTipText = "TestScript" ; Change this to the text you require

HotKeySet("q", "_Search")

Opt("TrayMenuMode", 3)

TrayCreateItem("One")
TrayCreateItem("Two")
TrayCreateItem("Three")
TrayCreateItem("")
$mExit_Item = TrayCreateItem("Exit")
TraySetState()
TraySetToolTip("TestScript")


While 1
    If TrayGetMsg() = $mExit_Item Then Exit
WEnd

Func _Search()

    $hTaskBarHandle = WinGetHandle("[Class:Shell_TrayWnd]", "")

    ; Find main systray handle and look there first
    $hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]")
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf
    $iSystray_ButtonNumber = Get_Systray_Index($sTipText)
    If Not @error Then
        _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
        Exit
    EndIf

    ; Click on button to open hidden icons
    ControlClick($hTaskBarHandle, "", "[CLASS:Button; INSTANCE:1]")
    ; Wait for window and then get handle
    WinWait("[Class:NotifyIconOverflowWindow]")
    $hSysTray_Handle = ControlGetHandle("[Class:NotifyIconOverflowWindow]", "", "[Class:ToolbarWindow32;Instance:1]")
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf
    ; Now look in hidden icons
    $iSystray_ButtonNumber = Get_Systray_Index($sTipText)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Error", "Could not find icon")
    Else
        _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
        Exit
    EndIf


EndFunc   ;==>_Show

Func Get_Systray_Index($sText)

    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf

    ; Look for  tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sText) > 0 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return SetError(1, 0, -1) ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc   ;==>Get_Systray_Index
That works fine for me - how about you? :)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

junkew,

 

Works good also on my machine

Excellent - thanks for letting me know. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I will try it bit later, because now i have other alot more imporant things to do, and i will post feedback, thanks to all of you :)

Edit: missing include

#include <MsgBoxConstants.au3>

:P

Edited by JustSomeone

Share this post


Link to post
Share on other sites

#15 ·  Posted

Melba32, wanting to say "Thank you".  The code that you shared in this thread has been way helpful!  Just a wee bit, it's helped hundreds of paramedics pay less attention to the technology, and more attention to their patient.

Share this post


Link to post
Share on other sites

#16 ·  Posted

EdWilson,

Thank you for having taken the trouble to post - you have no idea how happy I am to hear that I have helped these wonderful people in some way, however small.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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