Mik987 Posted February 8, 2014 Share Posted February 8, 2014 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 More sharing options...
somdcomputerguy Posted February 8, 2014 Share Posted February 8, 2014 Can you not just open 'Windows Update' another way? Maybe Run or ShellExecute whatever program runs from clicking on that line in the drop-down. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 8, 2014 Moderators Share Posted February 8, 2014 Mik987,Assuming the systray menu is a standard Windows menu, this shows how to determine which one is highlighted (highlit?):expandcollapse popup#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 "" EndFuncPlease ask if you run into any difficulties using it. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mik987 Posted February 8, 2014 Author Share Posted February 8, 2014 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 More sharing options...
Moderators Melba23 Posted February 8, 2014 Moderators Share Posted February 8, 2014 Mik987,I think this should do what you need:expandcollapse popup#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 "" EndFuncIf you have problems understanding the code, then please ask - that is why we are all here. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Solution Mik987 Posted February 8, 2014 Author Solution Share Posted February 8, 2014 simply brilliant! wow! 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now