Jump to content

Select text from a dropdown box of an icon from the notification area


Mik987
 Share

Go to solution Solved by Mik987,

Recommended Posts

In windows 7, I am trying to 
 
1) select an icon from the system tray or notification area
2) right click on the icon
2) select the text from the dropdown box
 
for exampe
 
1) select the icon Action Center
2) right click on it with _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "secondary") from GuiToolbar.au3
3) select Open Windows Update
 
this is what I know how to do:
 
get a handle on the systray
find the icon I want
right click on it
 
then I use Send("{DOWN}{DOWN}{DOWN}")
 
because Open Windows Update is the third text in the dropdown box, I use 3 {DOWN}
 
First is Open Action Center
Second Troubleshoot a problem
Third Open Windows Update
 
what I would like is to select based on the text : "Windows Update" not knowing it is the third one in the list
 
my troubles:
 
no idea how to get a handle on the dropdown box, not even sure I need to.
 
once I have a handle, I guess I would use something like _GUICtrlToolbar_ClickAccel from GuiToolbar.au3 but do not know how or if it is the right way to do that.
Link to comment
Share on other sites

  • Moderators

Mik987,

Assuming the systray menu is a standard Windows menu, this shows how to determine which one is highlighted (highlit?):

#include <WindowsConstants.au3>
#include <GUIToolbar.au3>
#include <WinAPI.au3>
#Include <GuiMenu.au3>
#include <Misc.au3>

$hDLL = DllOpen("user32.dll")

Opt("WinTitleMatchMode", 2)

Global $hSysTray_Handle, $iSystray_ButtonNumber
Global $sToolTipTitle = "#########"  ; Add a unique section of the text of your tray icon tooltip here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Is the App running?")
    Exit
Else
    Sleep(250)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
    Sleep(250)
    Do
        Sleep(100)
        ConsoleWrite(GetPopUpSelText() & @CRLF) ; This will read the currently selected item <<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Until _IsPressed("0D", $hDLL) Or _IsPressed("1B", $hDLL)
    DllClose($hDLL)
    Exit
EndIf

Func Get_Systray_Index($sToolTipTitle)

    ; 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 wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc

Func GetPopUpSelText()

    Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
    Local $hWnd = $aPopUp_List[1][0]
    Local $sClass = $aPopUp_List[1][1]
    If $sClass = "#32768" Then ; This is a "standard" Windows API popup menu
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            For $j = 0 To $iCount - 1
                If _GUICtrlMenu_GetItemHighlighted($hMenu, $j) Then
                    Return _GUICtrlMenu_GetItemText($hMenu, $j)
                EndIf
            Next
        EndIf
    EndIf
    Return ""

EndFunc
Please ask if you run into any difficulties using it. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Thanks Melba23, this is indeed interesting code, but this is not what I am trying to do:
 
In some code I need to pass 2 strings: one you clearly identified is the text of the tray icon 
 
tootlip for example "Action Center", the second string is: "Open Windows Update".
 
So what I want to see Autoit do is: 
 
right-click on the icon for Action Center (the flag thingie)
 
then it shows the drop-down menu with 3 choices
 
then the cursor aim for "Open Windows Update", select it and the windows update from 
 
control panel opens.
 
I took that example because it should be available on all windows 7 but it should work 
 
for any icon located in the system tray.
 
What I understand your script is doing is waiting for me to select some text and write it to 
 
a console.
 
I am sorry if I do not understand your script, but I am fairly new with Autoit, and not able 
to infer the code I need, from your example.
Link to comment
Share on other sites

  • Moderators

Mik987,

I think this should do what you need:

#include <WindowsConstants.au3>
#include <GUIToolbar.au3>
#include <WinAPI.au3>
#Include <GuiMenu.au3>

Opt("WinTitleMatchMode", 2)

Global $hSysTray_Handle, $iSystray_ButtonNumber
Global $sToolTipTitle = "######"  ; A unique section of the text of your tray icon tooltip here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Global $sItemName = "#######"     ; The item text on which to click

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Is the App running?")
    Exit
Else
    Sleep(250)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
    Sleep(250)
    Do
        Send("{UP}")
        Sleep(50)
    Until GetPopUpSelText() = $sItemName

    ; Replace this with Send("{ENTER}")
    MsgBox($MB_SYSTEMMODAL, "Ready to click", "Item = " & $sItemName)

    Exit
EndIf

Func Get_Systray_Index($sToolTipTitle)

    ; 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 wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc

Func GetPopUpSelText()

    Local $aPopUp_List = _WinAPI_EnumWindowsPopup()
    Local $hWnd = $aPopUp_List[1][0]
    Local $sClass = $aPopUp_List[1][1]
    If $sClass = "#32768" Then ; This is a "standard" Windows API popup menu
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            For $j = 0 To $iCount - 1
                If _GUICtrlMenu_GetItemHighlighted($hMenu, $j) Then
                    Return _GUICtrlMenu_GetItemText($hMenu, $j)
                EndIf
            Next
        EndIf
    EndIf
    Return ""

EndFunc
If you have problems understanding the code, then please ask - that is why we are all here. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Solution
simply brilliant! wow!  :sorcerer:  :thumbsup:
 
I had a feeling I had the answer under my nose but I could not understand it.
 
the key is really GetPopupSelText.
 
Will try to decorticate it and understand it and call for help once I did some work.
 
Thank you so much Melba23
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...