Page 1 of 1

Navigating task tray icon context menus

Posted: Mon Mar 05, 2007 7:34 pm
by cmiller
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

Posted: Mon Mar 05, 2007 10:11 pm
by webops
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ö

Posted: Mon Mar 05, 2007 11:26 pm
by cmiller
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

Posted: Mon Mar 05, 2007 11:57 pm
by webops
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ö

Posted: Tue Mar 06, 2007 1:07 am
by cmiller
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);

Posted: Tue Mar 06, 2007 10:41 pm
by webops
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ö

Posted: Tue Mar 06, 2007 10:51 pm
by cmiller
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.

Posted: Wed Mar 07, 2007 6:59 pm
by cmiller
New version works like a charm.

Thanks
-cmiller