Unable to get handler of Context Menu

Class library usage, coding and language questions.
saurabh
Posts: 20
Joined: Fri Jul 20, 2007 1:11 pm
Location: India
Contact:

Unable to get handler of Context Menu

Post by saurabh » Fri Aug 03, 2007 8:58 am

In my application Context Menu is appeared only after right click mouse in current form it’s not the permanent child of current form so I am unable to get the control by FindChild(). I am doing right mouse click by this code. I am working in VS2003 using RanorexNet.dll.

form = Application::FindFormTitle("Alarm manager",Ranorex::SearchMatchMode::MatchExact,true,5000);
Mouse::MoveToControl(form);
Mouse::ButtonDown(MouseButtonType::RightButton);
Mouse::ButtonUp(MouseButtonType::RightButton);

Now my context menu has appeared and there is no control showing by Ranorex Spy. So I can not use FindContolName() as mentioned in VS2005Application. Only Element role and name is there.

To understand my problem better like if you want to automate to get display property window of your desktop through Ranorex then you have to do following steps
1.Mouse right click on your desktop window
2.Now Popup Context Menu will appear
3.Now go to the properties item in Popup Context Menu
4.Click on properties item
5.now Display Properties window has opened.
If you will simultaneously observe the control and element value for each step through Ranorex spy. You will find when you would do right click ,Popup Context Menu will appear with Element Role: window and Name:context.
Now go to the properties Item it will appear with Element Role:MenuItem and Name:Properties.
Now I want to click on properties so it should open Display Properties Window for your Desktop.I have written following in the continuation of above code but it is not working:

Element *context = form->Element->FindChild(Ranorex::Role::Window, "Context");
Element *MenuItem1 = form->Element->FindChild(Ranorex::Role::MenuItem , "Hide Controls");
Mouse::MoveToElement(MenuItem1 );
Mouse::ClickElement(MenuItem1 );

Note:Here “Hide Controls” is one of the Menu item of Popup Context Menu in my application here you can replace this with Menu Item “Properties “

Please provide me correct code ASAP. Its argent.
Thanks in Advance!
Regards,
Saurabh Shrivastava
GE Global Research
Bangalore India

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

Post by admin » Fri Aug 03, 2007 4:05 pm

A context menu is a top-level window and not a child of a Form or Windows application.
You can popup a context menu and select an item as follows:

Code: Select all

// Click right mouse button
Mouse.ClickElement(element, MouseButtonType.RightButton);
// Wait 200msec
Application.Sleep(200);
// Select the context menu item with the name "Properties"
Application.PopupMenuSelectItem("Properties", 200);
or

Code: Select all

// Click right mouse button
Mouse.ClickElement(element, MouseButtonType.RightButton);
// Wait 200msec
Application.Sleep(200);
// Select the context menu item with the name "Properties"
ContextMenu.SelectItemText("Properties");
A standard context menu has a class name: #32768, if you get the same, then the sample above will work.
If you get an other class name in RanorexSpy, then you should search the context menu with the Application.FindForm function.

Jenö
Ranorex Team