How to get reference to a panel in Statusbar

Class library usage, coding and language questions.
sgreenfield
Posts: 17
Joined: Tue Oct 14, 2008 2:19 pm

How to get reference to a panel in Statusbar

Post by sgreenfield » Mon Nov 24, 2008 2:32 pm

I have the handle to the window in question but I don't see how to extract the text from individual panels in a msctls_statusbar32 control. Can you show an example?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Mon Nov 24, 2008 5:10 pm

You can use the element approach (see documentation) to get the text in the statusbar. Just search for all items of the Text role, e.g.:

Code: Select all

Control statusBar;
Element[] textElements = statusBar.Element.FindChildren(Role.Text);
foreach (Element elem in textElements)
    Console.WriteLine(elem.Name);
Regards,
Alex
Ranorex Support Team

sgreenfield
Posts: 17
Joined: Tue Oct 14, 2008 2:19 pm

Post by sgreenfield » Mon Nov 24, 2008 8:02 pm

I tried your suggestion - I verified that the hwnd is the correct for the statusbar and the object in non-null yet the 'textElements' array based on your code has nothing in it. Any ideas???

IntPtr hwndStatus = GetMainPlatformWindow().FindStatusBar(59393).Handle;
if (null != hwndStatus)
{
RX.StatusBar ctlStatusBar = new Ranorex.StatusBar(hwndStatus);

if (null != ctlStatusBar)
{
RX.Element[] textElements = ctlStatusBar.Element.FindChildren(RX.Role.Text);
foreach (RX.Element elem in textElements)
{
string strItem = elem.ToString();
}
}

sgreenfield
Posts: 17
Joined: Tue Oct 14, 2008 2:19 pm

Post by sgreenfield » Mon Nov 24, 2008 8:05 pm

I should add one more piece of information - the statusbar has some owner-drawn objects in it. They show up using Spy as garbage buffers but I do see the correct number of items and for the items using pure text, that is visible in spy as well.

Stumped.

sgreenfield
Posts: 17
Joined: Tue Oct 14, 2008 2:19 pm

Post by sgreenfield » Mon Nov 24, 2008 8:24 pm

Another interesting tidbit - the following line of code:

int nChildCount = ctlStatusBar.Element.GetChildCount;

I used this to see just how many elements Ranorex saw and that came back 7 when there are actually 12. Five of the strings are owner drawn colorized text or graphics images so I think my last comment is on to something.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Tue Nov 25, 2008 9:47 am

The element of a control always has 7 children with the 4th child actually corresponding to the control's role (i.e. the 4th child of a button control's element has the Button role). The other 6 children describe the windows state, it's scrollbars, system menu and so on. The logical UI child elements of a control are actually children of that 4th child element. It's a speciality of MSAA that everyone runs into once.

I thought that you are using a standard statusbar. If your statusbar panels are ownerdrawn, you need to inspect them with RanorexSpy and use their Role in the FindChildren statement. The Text role will obviously work only if all panels in the statusbar have that role.

Regards,
Alex
Ranorex Support Team

sgreenfield
Posts: 17
Joined: Tue Oct 14, 2008 2:19 pm

Post by sgreenfield » Tue Nov 25, 2008 6:24 pm

I changed the line of code to this:

RX.Element[] textElements = sb.Element.FindChildren(RX.Role.ListItem);

If I look at the text property for this statusbar (sb), I see the text for the first panel ("For Help, press F1"), but given the code you supplied I still get nothing in the array.

I must be missing something.

sgreenfield
Posts: 17
Joined: Tue Oct 14, 2008 2:19 pm

Post by sgreenfield » Wed Nov 26, 2008 2:02 pm

Not sure if you saw my last post but am I missing something?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Wed Nov 26, 2008 3:08 pm

If the panels in your statusbar are really of type ListItem, then the FindChildren code should work and get you all the elements of that role that are descendants of the statusbar control.

Perhaps the panels are not children of the statusbar? Did you try searching from another control, e.g. the parent control of the statusbar?

You can even try to use Ranorex Spy from our brand new Ranorex 2.0 Technology Preview (download it here). It's only a preview version (so pre-beta), but it will show you a tree of the elements in your application.

Regards,
Alex
Ranorex Support Team

sgreenfield
Posts: 17
Joined: Tue Oct 14, 2008 2:19 pm

Post by sgreenfield » Wed Nov 26, 2008 3:30 pm

Actually, that's what I did - the array is empty yet Spy shows everything. That's why I was at a loss to figure it out. I'm truly stumped.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Wed Nov 26, 2008 4:33 pm

If the spy shows the values you need, you can also get the values in code. Ranorex Spy uses the same library.

As I said before, the only thing I can think of that you are searching from the wrong control. You can try to use Ranorex 2.0 Preview or send us a sample application via email.

Regards,
Alex
Ranorex Support Team