1. Starting Guide

<< Click to Display Table of Contents >>

Navigation:  1. Starting Guides >

1. Starting Guide

1.9. Locating Child-Windows

Previous Top Next


Starting Guide

 

Childwindows and how to locate them

What are these child-windows and why do we need them?

 

clip0500

 

What is a child-window and why do we need it?

 

Before you start reading this chapter, make sure you are familiar with

6. Selecting the Application (Topwindow)

 

At this point i assume that you know the terms:

- Top-Window

- Window-Handle

and you should also be familiar with the chapter

5. Application and PID

means you should know what a process is and what a PID is.

 

Again we take a look on a window here.

 

graphic

 

This is one of the Test-Applications in the "Sample Apps" Subfolder of your Installation folder*. In fact its not really the Application its just the Application window. Because we control the application via the window buttons and controls, we often think of the application as the window.

 

In this chapter we are not going to talk more about the whole window (the Top-Window). Instead we will take a look on the buttons and text-boxes on this window.

These are the controls with which you control the application. And in fact, that is why they are called "controls". You can read their text. See if they are enabled or disabled.

You can press a button or type text into a text box (while not in this application). And now let me lift the secret about Child-Windows.

 


 

What are "Child-Windows"?

 

So far it belongs to us, we can safely assume that Childwindows  and "Controls" are just the same. A button is a child window. A text-box is a child-window. There are 50 child-windows in that Top-Window we see above. Technically for windows the Hierarchy of "Process, Top-Window and Child-Windows" look like this:

 

graphic

 

To understand it a bit better, we need to know that the Windows OS protects the Memory in which an Application resides from any access through other applications. If an application tries to read or write behind that Protection Border, you will see that application crash with one of those GPF's (General Protection Fault) Error Messages you know.

And now imagine that in this protected Application Memory there is everything inside that belongs to that application, that includes the application windows.

 

Now back to the picture above. Below the Top-Window you can see a lot of Buttons and other Child-Windows. They are childs from that Top-Window. If the Top-Window is been destroyed (closed) all of these Child-Windows are also history.

 


 

What can we do with child-windows?

 

- we open them together with their Top-Window, by starting their application

- we can handle them according to their role (press a button, pull a slider etc.)

 


 

Using the robot you get advanced powers with child-windows:

 

Using the robot we have more options, about what we can do with child-windows.

We can:

- change their window position and size

- minimize it (yes you can really minimize a child-window using the SWS.m command)

- maximize it

- if it was minimized or maximized, we can "normalize" it, to its normal size and position

- and finally we can close it

- we can disable any window

- if it was disabled, we can enable the window

- we can make the window invisible or

- if its invisible, we can make it visible again

we can also

- change its displayed text using the SDT.-command

and do a lot more such things, depending on what sort of window we have to deal with.

 


 

Now its time to tell you a secret about child-windows.

This time its maybe not really a secret, if you have read the chapter about Top-Windows. Yes, its true. Child-Windows do also each have its unique window handle. A button has a window handle. As well as a checkmark or a textbox or whatever. They just look exactly like window-handles from top-windows. You can not see any difference.

Only if you look into the windows-inspector you will see that ...

 

graphic

 

The Top-Window is at the Top of the List and has a Level (the number on the very left) of "00". The child windows are below the Top-Window. They start with a Level of "01".

 

The Inspector will show you all windows below the mouse-pointer. He will show you the Level, the window handle and in the first line you see a "CC:50". This means that this Top-Window has 50 Child-Windows. Next in the Middle part you will see the "window class" and then a Pipe-Symbol (|) followed by the window-text.

 

On the right side in the Inspector you will see the actual Mouse-position relative to the window in which the mouse is in. And then again a pipe followed by the size of that window/child-window.

 

Below you can see the position of the mouse in Screen-coordinates (relative to the desktop window). "Screen: 0282,0568".

 


 

Now, how do we locate Child-Windows (buttons etc.)?

 

We do it using the SCW. command and in the same way like with Top Windows.  While we have some more options with Child-Windows, then we had with Top-Windows.

Top-Windows do mostly not have a usable Window-ID.

Top-Windows do not have a "depth" because they are always on Level "00".

Child-Windows may have a valid ID and they always have a (depth=) Level of "01" or higher. Because they re below a Top-Window or below other Child windows in the Window-Hierarchy.

These are additional parameters we can use when addressing child-windows.

 

Knowing all this, we can locate a Top-Window and a button inside this Top-Window like this:

 

STW.ct|PBWindowClass:0|BCS - Testform

' Locate the Child-Window

' c - the class must contain the word "Button"

' t- the text on the control must contain the phrase "&Next"

' w - wait up to 5 seconds for the window

SCW.ctw|Button|&Next|5

' Mouse Move to the center of the located window rectangle

MMV.

 

If you have problems to understand the parameters in the SCW., see the chapter

4. The Prototype Parameter System

 


 

The final test

Now lets if you can really do it.Lets make a test.You know there is a built in recording feature, but this time we will make it "from hand".

Take a look on the picture below.

 

graphic

 

It shows the windows-Inspector while the mouse is over "button 3" in our TestApp. This is the button we want to click. Lets make a complete script to locate a child-window "button 3" and click on it. As said before, you find the TestApp in the "Sample Apps" folder in the Installation folder* of the program. I recommend that you start it now, then we can make a practical exercise together.

 

How do we start?

 

We always need to locate the Application-Window (Top-WIndow) first. This is  done using the STW. command.

 

What parameters will we use?

 

We will use the window caption "TestApp" and we'll use a piece of the window class. As we can see in the Windows-Inspector, the complete window-class is "PBWindowClass:0". We do not want to write so much. We just need a unique part out of it. We take "BWindowC". This is completely valid as we can always just specify a part of a text.

 

We write:

' "bwindowc" is a part of the full classname as its shown

' in the Window-Inspector

STW.tc|TestApp|BWindowC

 

Now lets try if this works. We add one line:

 

STW.tc|TestApp|BWindowC

MMV.

 

and start our script. What happens?

The Mouse-Pointer will drive into the center of the located window.

 

To be 100% sure we have located the right window, we can use this:

 

STW.tc|TestApp|BWindowC

HTV.$$MYH

 

and start our script. We get this result. Watch number 34408540. Its exactly the same number, thar we see in the windows-inspector for Level "00". This proofs that we have located the right Top-Window. No doubt!

 

graphic

 

We are now inside the Application window. Now we must locate the button. We want to locate "button 3". In this case we will use the window-class and a text-part for the SCW.-command.

We write this:

 

STW.tc|TestApp|BWindowC

SCW.ct|butt|n 3

MBX.#hwn#

 

and start our script. We get the result below.

 

graphic

 

again this is exactly the same number that we see in the window inspector. This proofs that we have located the right window. Now lets make a click on it. To click on a button or whatever, we have many choices, how to click. In this case we will make a very normal Click with the left mouse-button. Just as if we would have done it manually. We write.

 

STW.tc|TestApp|BWindowC

SCW.ct|butt|n 3

MLC.

 

Start the script and watch what happens.

 

Ok, we will take one more example from this Area. Take a look on the picture below. As you can see, we have two Buttons "Button 2". How can we handle this situation?

This time, we will use the "n" flag. It gives us the option to count the results and use result Nr.?, in our case we want to click on the second "fitting button". Let's try this first without click, just by moving the mouse there.

 

STW.tc|TestApp|BWindowC

SCW.ctn|butt|n 2|2

MMV.

graphic

 

But ... the mouse moves to the first button!  What is wrong here?

The answer is: nothing is wrong. We have no warranty, that the optical placement of a button anywhere in a Window is consistent with it's "count number". Technically the question is rather in which sequence the buttons have been created by the application. But we do not know the sequence, because this is up to the programmer. What we do is, we will just change the number to "1".

 

STW.tc|TestApp|BWindowC

SCW.sctn|butt|n 2|1

MMV.

 

That was the whole secret. Try and find the right number. No we just need to change the Move (MMV.) to a Click. In this case we have chosen another Mouse-Click, that will not move the mouse around, but just click. (MLE..).

 

STW.tc|TestApp|BWindowC

SCW.sctn|butt|n 2|1

MLE.

 

And thats all for now!

This was the chapter about locating child-windows. Take some time and experiment with it.

I am sure you will like it!

 

 


* the Installation folder is the folder, where you have installed the robot program.