How to get reference to a panel in Statusbar
-
- Posts: 17
- Joined: Tue Oct 14, 2008 2:19 pm
How to get reference to a panel in Statusbar
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?
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
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.:
Regards,
Alex
Ranorex Support Team
Code: Select all
Control statusBar;
Element[] textElements = statusBar.Element.FindChildren(Role.Text);
foreach (Element elem in textElements)
Console.WriteLine(elem.Name);
Alex
Ranorex Support Team
-
- Posts: 17
- Joined: Tue Oct 14, 2008 2:19 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();
}
}
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();
}
}
-
- Posts: 17
- Joined: Tue Oct 14, 2008 2:19 pm
-
- Posts: 17
- Joined: Tue Oct 14, 2008 2:19 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.
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.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
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
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
-
- Posts: 17
- Joined: Tue Oct 14, 2008 2:19 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.
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.
-
- Posts: 17
- Joined: Tue Oct 14, 2008 2:19 pm
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
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
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
-
- Posts: 17
- Joined: Tue Oct 14, 2008 2:19 pm
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
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
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