Window Analysis - Tutorial

 

How to enter text into an EditBox control

This tutorial is going to teach you how to write text into the EditBox (control) of Notepads 'File | Save As' dialog.

Step 1:

Before you begin writing the script, you will need to bring the dialog you are interested in interrogating, up on the screen. To launch Notepad, simply go to the Start Menu, select Run, and type notepad.exe. At this point Notepad should be launched and on the screen. (if not, please repeat step one)

Step 2:

Now that Notepad is launched and on the screen, we need to bring up the 'File | Save As' dialog. This can be done, by selecting the File menu, then select 'Save As' from the menu. At this point you should see a dialog, with the window title 'Save As' on the screen. (if not, please repeat steps one and two)

Step 3:

Now that the Notepad 'Save As' dialog is on the screen, we are ready to interrogate the dialog with the Windows Analysis Script.

What does the Windows Analysis script do?

The Windows Analysis script (analysis.wbt) creates a report on the windows visible at the time the report is run.

The basic technique is to open the application and get the dialog boxes you are interested in displayed on the screen.

The Window Analysis script will display output detailing the contents of the window in question.

How do I use it?

Run the script, by double clicking on analysis.wbt (which is most likely located in the WinBatch\Samples subdirectory).

A dialog will appear that is asking you whether or not to ignore hidden windows. Generally you will choose Yes, which will only display visible windows. Press the Yes button on this dialog.

 

OkToIgnore.GIF

 

A dialog with all the visible window titles, will appear. Choose the window title 'Save As' from the dialog, then press Ok. The Window Analysis script will process and output a dialog displaying Information about the Save As Window.

 

WinList___Tut1.GIF

 

It will look some thing like this...

 

 

· What is the Control Manager Extender?

· Overview of Control Manager Usage

· Types of Controls

 

 

 

Analysis___Tut1.png

 

The Parent and Child columns display the sequence of the various controls in the Window. The rest of the columns display information about each control, such as: CLASS, ID, NAME,  as well as other helpful information.

 

Step 4:

At this point the Windows Analysis' output should be on the screen. (if not, please repeat step three)

Explanation of the Windows Analysis output…

Information is listed by columns.

The parent and child columns will tell you where a particular control falls in the hierarchical scheme of things. Meaning, relationship of parent-to-child, and their sequential order.

  • CLASS column lists the 'types' of controls.

  • ID column lists each individual controls identifer. In other words, an id number that is associated to that particular control.

  • NAME column lists the title of the control, if any.

  • WNDSTYLE column lists the Window style.

  • WNDSTYLEEX column lists the Window extended style.

  • CLASSSTYLE column lists the Class style.

 

Step 5:

Now, that we understand the structure of the Windows Analysis output, a little better…

For this example, we are interested in six things, the top level parent, DUIViewWndClassName control, DirectUIHWND control, FloatNotifySync control, ComboBox control and Edit Control.

You will always need to get a handle to a top level parent window first. This can be done using the DLLHwnd function. As follows:

 

parentHwnd = DLLHwnd( 'Save As' )

 

DUIViewWndClassName, DirectUIHWND, FloatNotifySync and ComboBox   ( under the column heading CLASS) are important because we will need to get a handle to it in order to drill down to the Edit control.

Edit ( under the column heading CLASS) is important because that is the control that we want to fill in with the filename into Notepad.

 

 

Analysis___Tut1.png

 

 

The very first row of any Window Analysis script output should always contain information about the PARENT Window.

Now that we have a handle to the parent window using DllHwnd. We are interested in the Edit control.

You will notice the first GREEN column of that row is the Child5 column. What this tells you, is that the edit box control is the 5th child window in the list of sequential controls. The CLASS is Edit, which is the same as the type Edit. The ID number is 1001. And there is no TITLE, in this case.

It is important to know, that this control falls under the 5th child window in the list of sequential controls because, it tells us how far we need to 'drill down' to get the handle to the control. This will be explained more thoroughly at a later point.

 

 

 

Step 6:

Lets begin to write the script.

We are using the Control Manager extender, therefore we need to include the following statement, that adds the extender:

 

AddExtender( 'wwctl44i.dll',0,'wwctl64i.dll' )

 

As mentioned previously, we first need to get a handle to the top level parent window. This can be done as follows:

 

parentHwnd = DLLHwnd( 'Save As' )

 

Notice: the window TITLE, we handed to the function DLLHwnd is EXACTLY the same as, it is output by the Windows Analysis.

We now need to 'drill-down' to the control, using the cWndby__ functions.

 

What is meant by drill-down?

It means that we need to get a handle to every 'top-level' control, starting with the top level parent and working our way down through the child hierarchy. You can work down from the parent to the desired lower level "child" window by using the cWndBy__ functions to do this.

 

Listed by ease-of-use (easiest/best choice to most complex):

cWndById

cWndByName

cWndByClass

cWndBySeq

 

First, I see if a window at a particular level has a unique ID. If so I prefer to use that. If two windows at the same level have the same ID, then I see if the window names (or titles) are different. If not, then I check the class of the windows. And finally resort to the sequence number of the window.

Since the control we are attempting to get the handle to, does not have a distinctive ID or NAME, we can then simply use the cWndbyClass function to drill down and retrieve the handle to the edit box control.  

As you can see from the output the Edit control is buried under the DUIViewWndClassName, DirectUIHWND, FloatNotifySink and ComboBox controls. This means that we must first get handle to these controls. This can be done as follows:

 

C1 = cWndByClass ( parentHwnd, 'DUIViewWndClassName')

C2 = cWndByClass ( C1, 'DirectUIHWND')

C3 = cWndByClass ( C2, 'FloatNotifySink' )

C4 = cWndByClass ( C3, 'ComboBox' )

editHwnd = cWndByClass ( C4, 'Edit' )

 

We now have a handle to the Edit control. Using the function cSetEditText we can fill in the control with the file name, we would like to save the file as…

 

cSetEditText( editHwnd, 'C:\Temp\Test.txt' )

 

At this point your code should read as follows:

 

AddExtender( 'wwctl44i.dll',0,'wwctl64i.dll' )

parentHwnd = DllHwnd( 'Save As' )

C1 = cWndByClass ( parentHwnd, 'DUIViewWndClassName')

C2 = cWndByClass ( C1, 'DirectUIHWND')

C3 = cWndByClass ( C2, 'FloatNotifySink')

C4 = cWndByClass ( C3, 'ComboBox' )

editHwnd = cWndByClass ( C4, 'Edit' )

cSetEditText( editHwnd, 'C:\Temp\Test.txt' )

 

 

Step 7:

Lets add to the script.

At this point we have the basic code that will get a handle to the 'Save As' dialog, then it gets a handle to the edit control and finally put the line 'C:\Temp\Test.txt' into the edit control.

There are a few more things we may want to add. For instance, we probably want our WinBatch script to launch Notepad, wait for the window to appear and bring up the 'Save As' dialog, automatically. The code to do this, looks like the following:

 

Run("notepad.exe","")

SendMenusTo("~Notepad","FileSaveAs")

WinWaitExist("Save As",5)

 

We have now completed the script. Here is what the completed script should look like:

 

 

Completed script

 

AddExtender( 'wwctl44i.dll',0,'wwctl64i.dll' )

Run("notepad.exe","")

SendMenusTo("~Notepad","FileSaveAs")

WinWaitExist("Save As",5)

parentHwnd = DllHwnd( 'Save As' )

C1 = cWndByClass ( parentHwnd, 'DUIViewWndClassName')

C2 = cWndByClass ( C1, 'DirectUIHWND')

C3 = cWndByClass ( C2, 'FloatNotifySink')

C4 = cWndByClass ( C3, 'ComboBox' )

editHwnd = cWndByClass ( C4, 'Edit' )

cSetEditText( editHwnd, 'C:\Temp\Test.txt' )

exit