Can't find Control Name

Class library usage, coding and language questions.
GuiTester
Posts: 4
Joined: Mon Sep 11, 2006 6:49 am

Can't find Control Name

Post by GuiTester » Thu Sep 14, 2006 7:11 am

I have a C#.NET based windows application. I used the RanorexSpy to find out the class name, control name of the application. I got the values for Caption/text and Class name fields. But, the Class name and Control id fields are empty.

In this case, which field should I use to reliable get a handle to the application?

Thanks in advance.

GuiTester
Posts: 4
Joined: Mon Sep 11, 2006 6:49 am

Post by GuiTester » Thu Sep 14, 2006 7:26 am

For the time being, I used the class name which looks something like "WindowsForms10.Window.8.app...".

When I call 'FindFormClassName' method, I get a dialog box with the error 'CoInitialize error'. Any idea what this means?

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

Post by admin » Thu Sep 14, 2006 9:27 pm

> In this case, which field should I use to reliable get a handle to the application?

An application has no "Control name" and no "Control Id", only controls have these properties. You should find an application with the Application.FindFormTitle function:
(See also the samples in the Samples directory)

Code: Select all

Form form = Application.FindFormTitle("Title of the application");
You should use the FindFormClassName method only, if your application has no unique title.

> I get a dialog box with the error 'CoInitialize error'. Any idea what this means?

We use COM in RanorexCore and COM Interop in RanorexNet, so we need a SingleThreadedAppartement.
This error can happen, if the main thread hasn't the attribute [STAThread]
See also: http://www.ranorex.com/net/samples/visu ... teaser/11/

[STAThread]
static int Main(string[] args)

Jenö Herget
Ranorex Team

GuiTester
Posts: 4
Joined: Mon Sep 11, 2006 6:49 am

Post by GuiTester » Fri Sep 15, 2006 7:38 am

Thanks for the reply. I fixed the CoInit problem.

I used your example and tried to programmatically get the application handle, the properties window, the solution explorer in my application. I had trouble with the menu bar. If I see the menubar through RanorexSpy, it doesn't have a control name or a caption text. It has a control id, and a class name which is like 'WindowsForms10.Window.8.app.0.b7ab7b #34'.

Is there a way I can get a menubar object without using the title?

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

Post by admin » Fri Sep 15, 2006 11:27 pm

> Is there a way I can get a menubar object without using the title?

If your menu bar has no control name, then you have an old style menu bar with menu handle, not a menu strip.
You can automate such a menu as follows:

Code: Select all

Menu menu = new Menu(form);
if (menu != null)
{
    // Get the item count of the first submenu
    int ret = menu.GetItemCount(1);
    Console.WriteLine("  GetItemCount(1)={0}", ret);
    
    // Get the text of the second menu item of the first submenu
    string itemText = menu.GetItemText(1, 2);
    Console.WriteLine("  GetItemText(1,2)={0}", itemText);
    
    // Select a menu item
    ret = menu.SelectItemText("Submenu2", "Submenu2Item1");
}
See the documentation for other menu functions.

Jenö Herget
Ranorex Team