Jump to content

How to get text from right-click (context menu) of tray icon?


Mbee
 Share

Recommended Posts

Hi, folks!

Wow, do I love AutoIt!  My endless thanks to its creators and maintainers! :thumbsup:

Anyway, here's my issue. As always, there are several icons/items in my system tray. I need to get the text that's displayed if I right-click on a specific one of those icons.

It's easy to find the index number and text of the specific, third-party application's tray icon (using _GUICtrlToolbar_GetButtonText() and the like), but I can't figure out how to get the text that would be shown if one right-clicked on the context menu of that icon. And it needs to work with both Windows 7 and 8.

You see, the context menu of the tray icon of a particular third-party app shows some status info that I need, and there's no other way to obtain it.

Please advise...

Link to comment
Share on other sites

  • Moderators

Mbee,

I showed how to get the text from a tray menu in this thread. Take a look and see if you can get it to work - I will be back this evening if you get stuck. :)

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 bunches, Maestro Melba23!

Sadly, the third-party app I'm interested in reports "Non-standard Pop-up Menu".  Bummer! :(

(That's just my luck...  By the way, your code works great for other apps I've tried.) 

I really don't want to make a nuisance of myself, and I google like crazy trying to find solutions on my own, but I'm afraid I'll need more assistance with this one...

 

Mbee,

I showed how to get the text from a tray menu in this thread. Take a look and see if you can get it to work - I will be back this evening if you get stuck. :)

M23

 

Link to comment
Share on other sites

  • Moderators

Mbee,

 

the third-party app I'm interested in reports "Non-standard Pop-up Menu"

Always seems to be the case when you really do not need it! :D

Could you post an image of the menu and the status value you are trying to read? Although at the moment I must admit that I do not have any ideas, seeing an image might perhaps suggest some other way to get at 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 for sticking with me, Melba23!

I've attached captures of the tray icon context menu in both of the main states I'm interested in (I had to use the timed capture feature of SnagIt 11 to get them). It would be great to get the info from the next level too, but since getting just the main state info is going to be difficult enough, I'm definitely not going to get greedy!

Here they are:

Ready to record: post-80483-0-99084300-1407727671.png

Currently recording: post-80483-0-48637600-1407727671.png

We may be thinking along the same lines (and computergroove too, it seems): Maybe we should forget trying to read the text and instead grab the context menu as an image and compare it internally to either of the two known pre-captured images.  But it seems to me that one major problem with that idea is that different screen resolutions will produce different images (obviously), and so I'd need some sophisticated math/graphics functions to internally resize the images and perform some kind of "close enough" comparisons (since exact bit-for-bit matches would never work).  So maybe that idea won't fly either!

Finally, I'd feel guilty as hell if this turns out to be a real chore for you, Melba!  If it sounds like a fun challenge, then cool, but otherwise please know that I'll be fine without it :whistle:

Thanks again!

Mbee,
 
Always seems to be the case when you really do not need it! :D

Could you post an image of the menu and the status value you are trying to read? Although at the moment I must admit that I do not have any ideas, seeing an image might perhaps suggest some other way to get at it. ;)

M23

Edited by Mbee
Link to comment
Share on other sites

  • Moderators

Mbee,

Looking at those images, PixelCheckSum instantly springs to mind. I assume that the initial state of the add is the upper image - so I reckon that clicking on the icon to open the menu would allow us to capture the checksum of the "Ready" menu before you ever start the app. That way the screen resolution, etc do not matter as the image will be that of the machine on which the app is running. Subsequent "peeks" just confirm whether the checksum is the same as the initial one or not and so determine the current state. :)

And yes, it is a "fun challenge" so do not feel bad about asking - it is problems like this that keep me interested in coding. I will have a think about how we might do this while I am travelling over the next few days and I will get back to you - of course by all means have a go yourself in the meantime as well. ;)

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

  • Moderators

junkew,

As you know about such things, do please help Mbee to achieve his aim. :)

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

@Melba23: Forum rule, people show first some effort themselves (not seen any source or classnames so far in this thread) but anyway a demo below based on the simplespy.au3

unclear which third party app we are trying to catch. Screenshots just look like a regular context popup

 

steps

1. download stuff from '?do=embed' frameborder='0' data-embedContent>>

2. play with simplespy.au3 and look at the sourcecode it directly gives you

3. For every element you want to do something press in simplespy ctrl+w and copy the demo code to a new script

4. repeat 3 for every element

in my case--mouse to taskbar, ctrl+w, mouse to traywindow and button, ctrl+w, mouse to javaupdatebutton, ctrl+w, mouse to cancel option in menu, ctrl+w and we have all basic information

5. comment this out with #cs/#ce

6. make your own cleaned up code and change setfocus actions to click, rightclick, move etc.   90% worked immediately

 

see result for Java Update tray button (I do not have the application WayFarer/MFee has) could be that it doesn't work for the third party app menu but it should at least come to the point where the popupmenu is displayed

edit: seems to be avermedia RECentra http://gamerzone.avermedia.com/support/download/live_gamer_portable but as i do not have a device no contextmenu

setupcontrols are all recognized by spy during startup

 

edit2: split spy commented source from cleaned up part

 

#cs
;~ Spy recorded with ctrl+w and copy/paste
;~ Taskbar
;~ *** Standard code ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP2=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell_TrayWnd", $treescope_children)
_UIA_Action($oP2,"setfocus")
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_PaneControlTypeId;class:=ReBarWindow32", $treescope_children)
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Actieve toepassingen;controltype:=UIA_PaneControlTypeId;class:=MSTaskSwWClass", $treescope_children)
_UIA_Action($oP0,"setfocus")
_UIA_setVar("Actievetoepassingen.mainwindow","title:=Actieve toepassingen;classname:=MSTaskListWClass")
_UIA_action("Actievetoepassingen.mainwindow","setfocus")

;~ Hidden icons
;~ *** Standard code ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP1=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell_TrayWnd", $treescope_children)
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_PaneControlTypeId;class:=TrayNotifyWnd", $treescope_children)
_UIA_Action($oP0,"setfocus")
_UIA_setVar("NotificationChevron.mainwindow","title:=NotificationChevron;classname:=Button")
_UIA_action("NotificationChevron.mainwindow","setfocus")

;~ The java button information
;~ *** Standard code ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP1=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=NotificationOverflow;controltype:=UIA_PaneControlTypeId;class:=NotifyIconOverflowWindow", $treescope_children)
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Systeemvak voor overloop;controltype:=UIA_ToolBarControlTypeId;class:=ToolbarWindow32", $treescope_children)
_UIA_Action($oP0,"setfocus")
;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll("JavaUpdateAvailable.mainwindow", "title:=Java Update Available;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Java Update Available;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
_UIA_action($oUIElement,"click")

;~ The context menu cancelbutton
*** Standard code ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP0=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Context;controltype:=UIA_MenuControlTypeId;class:=#32768", $treescope_children)
_UIA_Action($oP0,"setfocus")
;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll("Cancel.mainwindow", "title:=Cancel;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Cancel;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree)
_UIA_action($oUIElement,"click")
#CE
;~ Above cleaned up leads to this
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)
Local $oTray=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell_TrayWnd", $treescope_children)
_UIA_Action($oTray,"setfocus")
Local $oNotify=_UIA_getObjectByFindAll($oTray, "Title:=;controltype:=UIA_PaneControlTypeId;class:=TrayNotifyWnd", $treescope_children)
_UIA_Action($oNotify,"setfocus")
Local $oChevron=_UIA_getObjectByFindAll($oNotify,"title:=NotificationChevron;classname:=Button", $treescope_children)
_UIA_action($oChevron,"click")

;~ Now the objecthierarchy has changed with the first chevron popup around
;~ Spy tells us that its somehow child of the desktop so directly copy/paste of the given spy code with exception of rightclick instead of click
Local $oP1=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=NotificationOverflow;controltype:=UIA_PaneControlTypeId;class:=NotifyIconOverflowWindow", $treescope_children)
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Systeemvak voor overloop;controltype:=UIA_ToolBarControlTypeId;class:=ToolbarWindow32", $treescope_children)
_UIA_Action($oP0,"setfocus")
;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll("JavaUpdateAvailable.mainwindow", "title:=Java Update Available;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Java Update Available;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
_UIA_action($oUIElement,"rightclick")

;~ Now the objecthierarchy has changed with the #32768 popup around
;~ And we click the cancelbutton
Local $oP0=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Context;controltype:=UIA_MenuControlTypeId;class:=#32768", $treescope_children)
_UIA_Action($oP0,"setfocus")
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Cancel;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree)
_UIA_action($oUIElement,"click")
Edited by junkew
Link to comment
Share on other sites

Hey, thanks again, Melba23!  Your idea of using PixelCheckSum() seems ideal for my simple needs.

It would appear that junkew imagines me to be far smarter and more experienced than I actually am :> , but may I take a moment and confess to my continued noobosity? :blink:  I'm tryin', but I'm hardly ready for prime time...

You see, I'm so ignorant I'm still trying to figure out how to determine the correct coordinates to pass to PixelCheckSum().  For example, when I try the following snippet (based on your kindly supplied code):

Local $ai_Rect
GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
$ai_Rect = _GUICtrlToolbar_GetButtonRect($hSysTray_Handle, $iSystray_ButtonNumber)
_ArrayDisplay( $ai_Rect, "Rect Coords")

... the result is [2, 0, 26, 38], no matter what values I use for MouseCoordMode and PixelCoordMode options.  Obviously, those values are problematic for two main reasons: (1) I have no idea what those coordinates are supposed to be relative to, and (2) they can't be correct relative to anything, since the context-menu bitmap in question (which I uploaded and posted above) is actually 140x90 pixels in size (not 24x38)!  So, what the heck?   I'm obviously misunderstanding something important that I should know, but don't...

But please enjoy your travels as best you can, Maestro!  I'm not in a hurry, and I'll continue trying to figure out how to use PixelCheckSum() on my own...

Take care!

 

Mbee,

Looking at those images, PixelCheckSum instantly springs to mind. I assume that the initial state of the add is the upper image - so I reckon that clicking on the icon to open the menu would allow us to capture the checksum of the "Ready" menu before you ever start the app. That way the screen resolution, etc do not matter as the image will be that of the machine on which the app is running. Subsequent "peeks" just confirm whether the checksum is the same as the initial one or not and so determine the current state. :)

And yes, it is a "fun challenge" so do not feel bad about asking - it is problems like this that keep me interested in coding. I will have a think about how we might do this while I am travelling over the next few days and I will get back to you - of course by all means have a go yourself in the meantime as well. ;)

M23

 

Link to comment
Share on other sites

Dear junkew, thank you for your profound (if rather complex) contribution!

I've spent several hours reading the links you've kindly provided as best I can, and through them you've opened my mind to concepts and capabilities of which I had been previously unaware.  I thank you for that.  The possibilities these technologies and APIs open up are quite impressive.

However, it appears you overestimate my knowledge and experience by a considerable degree (in other words, I'm still a noob).  Please understand that it will take me a good while before I can get up to speed on what you're providing to me.  I'm really trying, but I'm still struggling...

Yes, the third-party application I'm working with is AVerMedia RECentral. I've had my script essentially already done and working for some time now, but I've found that in very rare circumstances that app can behave in unexpected ways, so I'm trying to adapt my script to handle the rare event properly.

 

You mentioned to Melba23 that I had not provided any code samples, but for the life of me I can't imagine what I might have provided that would be of any value, since I have no idea how to solve the problem!  Getting the text from the tray icon's context menu doesn't work because AVerMedia didn't follow standard coding practices when developing RECentral.  That being the case, I have no idea where to even begin!

 

Please understand and have patience with me.

Thank you again.

Link to comment
Share on other sites

I have patience.

Things that help are

  • Which Windows version
  • 32 or 64 bits
  • classnames and output of all properties that are given by simplespy after you hover over an element and press ctrl+w
  • screenshot indicating which area is highlighted when you press ctrl+w
  • reproducer script on applications all people have and work like notepad, wordpad, chrome, internet explore, ...... 
  • check allways if you have the latest version of a UDF

As i do not have a working AVerMedia RECentral (I installed it but it complains I do not have the right device's) as such I can only tell you wat tho do as done above in steps 1 thru six.

1. Download the zip from the IUIAutomation thread
2. Download the WIP also including the simplespy.au3
3. Then make sure your contextmenu is shown and press ctrl+w and tell me which area you see highlighted
a. whole contextmenu
b. an item in the menu
if its b you can automate and you see in the output of simplespy the text of your menuitem.

The concepts for most automation technologies are similar
Everything you see as an element on the screen is having properties with values.
Identifying elements then normally can be done by searching like
Give me all elements that have <property 1>=<value 1> and <property 2>=<value 2>. More complex examples are with or combinations or regular expressions.
AutoIT functions recognize less controls then IUIAutomation is recognizing.

You should really see it as a tree where you want to go to a certain leaf to reach the leafs you have to describe the branches and subbranches how to come there.

The root is allways the desktop
Which has applications / parent windows
and each window has several levels before you come to the actual element

Another comparison for understanding can be a directory structure which you have to traverse.


As another starting example I would say try to reproduce my script creation on the chrome contextmenu when you have chrome.exe its just a 4 times pressing ctrl+w , copy the code to a new script and the fifth step is cleaning up the script.

I commented in the code what I did

Cleaning can be done in more detail to make scripts look nicer and more maintainable but it just directly works on my W7 and chrome.exe in the hidden icons area

;~ Step 1 Created by ctrl+w on hovering mouse above taskbar

;~ *** Standard code ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP2=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell_TrayWnd", $treescope_children)
_UIA_Action($oP2,"setfocus")
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_PaneControlTypeId;class:=ReBarWindow32", $treescope_children)
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Actieve toepassingen;controltype:=UIA_PaneControlTypeId;class:=MSTaskSwWClass", $treescope_children)
_UIA_Action($oP0,"setfocus")
_UIA_setVar("Actievetoepassingen.mainwindow","title:=Actieve toepassingen;classname:=MSTaskListWClass")
_UIA_action("Actievetoepassingen.mainwindow","setfocus")


;~ Step 2 Created by ctrl+w on hovering mouse above button that shows hidden pictograms and replace setfocus with click

;~ *** Standard code ***
;~ #include "UIAWrappers.au3"
;~ AutoItSetOption("MustDeclareVars", 1)

Local $oP1=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell_TrayWnd", $treescope_children)
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_PaneControlTypeId;class:=TrayNotifyWnd", $treescope_children)
_UIA_Action($oP0,"setfocus")
_UIA_setVar("NotificationChevron.mainwindow","title:=NotificationChevron;classname:=Button")

;~ Replaced with click _UIA_action("NotificationChevron.mainwindow","setfocus")
_UIA_action("NotificationChevron.mainwindow","click")


;- Step 3 Created by ctrl+w on hovering mouse above chrome button
;~ *** Standard code ***

;~ #include "UIAWrappers.au3"
;~ AutoItSetOption("MustDeclareVars", 1)

Local $oP1=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=NotificationOverflow;controltype:=UIA_PaneControlTypeId;class:=NotifyIconOverflowWindow", $treescope_children)
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Systeemvak voor overloop;controltype:=UIA_ToolBarControlTypeId;class:=ToolbarWindow32", $treescope_children)
_UIA_Action($oP0,"setfocus")
;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll("GoogleChrome.mainwindow", "title:=Google Chrome;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Google Chrome;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)

;~ Replaced with rightclick _UIA_action($oUIElement,"click")
_UIA_action($oUIElement,"rightclick")

;- Step 4 Created by ctrl+w on hovering mouse above context menu about menu item
;~ *** Standard code ***
;~ *** Standard code ***
;~ #include "UIAWrappers.au3"
;~ AutoItSetOption("MustDeclareVars", 1)

Local $oP3=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_WindowControlTypeId;class:=Chrome_WidgetWin_2", $treescope_children)
_UIA_Action($oP3,"setfocus")
Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_MenuBarControlTypeId;class:=", $treescope_children)
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_CustomControlTypeId;class:=", $treescope_children)
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_MenuControlTypeId;class:=", $treescope_children)
;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll("OverGoogleChrome.mainwindow", "title:=Over Google Chrome;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Over Google Chrome;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree)
_UIA_action($oUIElement,"click")


;~ Step 5 Remove the tomany includes and AutoItSetOption commands 

Steps like this

_UIA_setVar("Actievetoepassingen.mainwindow","title:=Actieve toepassingen;classname:=MSTaskListWClass")
_UIA_action("Actievetoepassingen.mainwindow","setfocus")

could also be written as 

_UIA_action("title:=Actieve toepassingen;classname:=MSTaskListWClass","setfocus")

but normally when I write longer scripts I move _UIA_setVar to as seperate section in my script and replace Actievetoepassingen.mainwindow with another logical name for endusers its just about maintenance the bigger your scriopt gets the more you want to have stuff like "title:=Actieve toepassingen;classname:=MSTaskListWClass" in a central area in your script to ease maintenance.

stuff like this you should probably change to your windows language but could be written to handle dutch and english like this

"Title:=((Actieve.*)|(Active.*))"

"title:=((Over Google Chrome)|(About Chrome))"

Edited by junkew
Link to comment
Share on other sites

and as additional exercise How the full cleaned script can look like (not fully sure if it works with the UIAWrappers that are not Work In Progress (WIP))
So spy gives you quick but complex script but once you now how to read it its not difficult to convert to something like below

#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

;~ Set all reference logical names

_UIA_setVar("Taskbar","Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell_TrayWnd")
_UIA_setVar("NotifyTaskbar","Title:=;controltype:=UIA_PaneControlTypeId;class:=TrayNotifyWnd")
_UIA_setVar("NotifyChevron","title:=NotificationChevron;classname:=Button")

_UIA_setVar("NotifyWindow","Title:=NotificationOverflow;controltype:=UIA_PaneControlTypeId;class:=NotifyIconOverflowWindow")

;~ Mainwindow naming is important to have this properly running otherwise framework does not know which searchcontext to use
_UIA_setVar("NotifyWindowTB.Mainwindow","Title:=Systeemvak voor overloop;controltype:=UIA_ToolBarControlTypeId;class:=ToolbarWindow32")
_UIA_setVar("ChromeButton","title:=Google Chrome;ControlType:=UIA_ButtonControlTypeId")

_UIA_setVar("ChromeContext.Mainwindow","Title:=;controltype:=UIA_WindowControlTypeId;class:=Chrome_WidgetWin_2")
_UIA_setVar("ChromeAboutMenu","title:=Over Google Chrome;ControlType:=UIA_MenuItemControlTypeId")


;~ Actual script
_UIA_Action("Taskbar","setfocus")
_UIA_Action("NotifyTaskbar","setfocus")
_UIA_Action("NotifyChevron","click")

; If we are to quick for screen so shortly wait till icons are properly (re)arranged
;~ sleep(5000)

_UIA_Action("NotifyWindow","setFocus")
_UIA_Action("NotifyWindowTB.Mainwindow","setFocus")

_UIA_action("ChromeButton","rightclick")

_UIA_action("ChromeContext.Mainwindow","setfocus")
_UIA_action("ChromeAboutMenu","click")
Edited by junkew
Link to comment
Share on other sites

Mbee, Try to run this code in Scite. The code sleeps for 10 seconds. This gives you time to open the context menu. Then it looks for open menus in the entire Desktop. There should only be one. If the script finds a menu, it prints the names of the menu items in Scite console.

 

#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

Sleep( 10000 )
MainFunc()


Func MainFunc()

  ; Create UI Automation object
  Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "UI Automation object error" & @CRLF )

  ; Get UI Automation element for Desktop
  Local $pDesktop, $oDesktop
  $oUIAutomation.GetRootElement( $pDesktop )
  $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "Desktop automation element error" & @CRLF )

  ; Condition to find menu controls
  Local $pCondition
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuControlTypeId, $pCondition )
  If Not $pCondition Then Return ConsoleWrite( "Property condition error" & @CRLF )

  ; Find menu controls
  Local $pUIElementArray, $oUIElementArray, $iElements
  $oDesktop.FindAll( $TreeScope_Children, $pCondition, $pUIElementArray )
  $oUIElementArray = ObjCreateInterface( $pUIElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray )
  $oUIElementArray.Length( $iElements )
  If Not ( $iElements = 1 ) Then Return ConsoleWrite( "Find menu controls error" & @CRLF )

  ; Automation element for the menu
  Local $pMenu, $oMenu
  $oUIElementArray.GetElement( 0, $pMenu )
  $oMenu = ObjCreateInterface( $pMenu, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oMenu ) Then Return ConsoleWrite( "Menu automation element error" & @CRLF )

  ; Condition to find menu items
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition )
  If Not $pCondition Then Return ConsoleWrite( "Property condition error" & @CRLF )

  ; Find menu items
  $oMenu.FindAll( $TreeScope_Children, $pCondition, $pUIElementArray )
  $oUIElementArray = ObjCreateInterface( $pUIElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray )
  $oUIElementArray.Length( $iElements )
  If Not $iElements Then Return ConsoleWrite( "Find menu items error" & @CRLF )

  ; Print menu item names
  Local $pUIElement, $oUIElement, $sName
  ConsoleWrite( "Menu items:" & @CRLF )
  For $i = 0 To $iElements - 1
    $oUIElementArray.GetElement( $i, $pUIElement )
    $oUIElement = ObjCreateInterface( $pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    $oUIElement.GetCurrentPropertyValue( $UIA_NamePropertyId, $sName )
    ConsoleWrite( "  " & $sName & @CRLF )
  Next

EndFunc

To test the code, you can right click the Desktop, and the script should print the items of the Desktop context menu.

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...