Navigating task tray icon context menus

Class library usage, coding and language questions.
cmiller
Posts: 7
Joined: Mon Mar 05, 2007 7:23 pm

Navigating task tray icon context menus

Post by cmiller » Mon Mar 05, 2007 7:34 pm

Hi Ranorex,

I'm having trouble finding the context menu of our applications' tray icon.

I'm able to get the element of the icon, but the icon has 0 children elements.

I have tried:
Using the Ranorex.ContextMenu class - it doesn't find the context menu of the icon
Right clicking on the icon and using Control.SendKeys - Control.SendKeys sends only to the primary application
Using the task tray as it's own form and using Application.SendKeys

any tips you could provide would be very appreciated

TIA,
cmiller

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Mon Mar 05, 2007 10:11 pm

Please read the post:

Trouble accessing Windows notification tray area.

(It's a Python sample in the reply for using the contexmenu of the Touch Pad, but you can do the same in C# with your application' tray icon.)

Code: Select all

hTaskTray = Ranorex.FormFindClassName("Shell_TrayWnd", 1, True, 5000) 
trayElement = Ranorex.ControlGetElement(hTaskTray)
notifyElement = Ranorex.ElementFindChild(trayElement, Ranorex.ROLE_SYSTEM_CLIENT, "", 'TrayNotifyWnd')
touchButton = Ranorex.ElementFindChild(notifyElement,Ranorex.ROLE_SYSTEM_PUSHBUTTON, 'Touch Pad')
if touchButton == None:
    print 'Touch button not found'
    return 1

Ranorex.MouseClickElement(touchButton,Ranorex.MOUSE_RIGHT_BUTTON)
Ranorex.Sleep(100)
Ranorex.ContextMenuSelectItemText('&Info')
Please post your C# code here if it works.

Jenö

cmiller
Posts: 7
Joined: Mon Mar 05, 2007 7:23 pm

Post by cmiller » Mon Mar 05, 2007 11:26 pm

Thank you for the code snippet, I converted it to C# but it is not working.

The ContextMenu.SelectItemText returns error -3.
As an exception the error is "The specified command could not be executed."

Code: Select all

Form hTaskTray = Ranorex.Application.FindFormClassName("Shell_TrayWnd", 1 , true, 5000);
                    
Element trayElement = hTaskTray.Element;
Element touchButton = trayElement.FindChild(Role.PushButton, "RanorexSpy");

if (null == touchButton)
{
     Logging.WriteToLog("Could not find icon");
     return Data.Result.FATAL;
}

Ranorex.Mouse.ClickElement(touchButton, Ranorex.MouseButtonType.RightButton);
Ranorex.Application.Sleep(100);
int error = Ranorex.ContextMenu.SelectItemText("About ...") ; //Returns error -3

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Mon Mar 05, 2007 11:57 pm

The code works for me, but the menu text has two spaces, between About and ...

Code: Select all

int error = Ranorex.ContextMenu.SelectItemText("About  ...");
(Don't ask me why, it's a cosmetic error)

Please use a & symbol if your menu text has a shortcut key.

Jenö

cmiller
Posts: 7
Joined: Mon Mar 05, 2007 7:23 pm

Post by cmiller » Tue Mar 06, 2007 1:07 am

Thank you for all the help, I'm able to navigate RanorexSpy now, but still having trouble with other icons.

I'm not able to GetItemText, SelectItemText or SelectPosition either of the two options in the Volume icon tray which controls the volume in windows XP.


Code: Select all

Form hTaskTray = Ranorex.Application.FindFormClassName("Shell_TrayWnd", 1 , true, 5000);
Element trayElement = hTaskTray.Element;
Element touchButton = trayElement.FindChild(Role.PushButton, "Volume");

if (null == touchButton)
{
    Logging.WriteToLog("Could not find icon");
    return Data.Result.FATAL;
}

Ranorex.Mouse.ClickElement(touchButton, Ranorex.MouseButtonType.RightButton);
Ranorex.Application.Sleep(1000);
string name = null;
int position = 2;

name = Ranorex.ContextMenu.GetItemText(position);
int error = Ranorex.ContextMenu.SelectPosition(position);

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Tue Mar 06, 2007 10:41 pm

We have released a new version V1.1.0 today.
I used this new version yesterday and it worked for both RanorexSpy and VolumeControl. We fixed a bug in the ContextMenu core and i think this version will also work with your application.

Please download, try the new version and inform us about the results.

Jenö

cmiller
Posts: 7
Joined: Mon Mar 05, 2007 7:23 pm

Post by cmiller » Tue Mar 06, 2007 10:51 pm

Thanks for all the help, I'll get the new version and give it a try.

I'll let you know the results as well.

cmiller
Posts: 7
Joined: Mon Mar 05, 2007 7:23 pm

Post by cmiller » Wed Mar 07, 2007 6:59 pm

New version works like a charm.

Thanks
-cmiller