Controls - Overview

 

The use of the Control commands can be a very powerful addition to macro building. We will attempt to explain some of the benefits of using these commands in this page and subsequent topics. But first, here is a definition of controls from Microsoft:

 

"A control is a child window an application uses in conjunction with another window to perform simple input and output (I/O) tasks. Controls are most often used within dialog boxes, but they can also be used in other windows. Controls within dialog boxes provide the user with the means to type text, choose options, and direct a dialog box to complete its action. Controls in other windows provide a variety of services, such as letting the user choose commands, view status, and view and edit text."

 

For our purposes, controls refer to the identifiable parts of a specific application window. Controls may include such things as a button, an edit box, a toolbar, a window title bar or other items. The control may be part of the main application window or be part of a child window (a window within a window).

 

 

Assigning Controls to Variables

A Control type variable contains the control information. There are two commands that can be used to obtain the control information and assign it to a Control variable.

 

The first choice would be to use the Get Control command. This launches a small utility and a pointer that is dragged over top of a control. The control information is captured and assigned to a variable. In this case the control information is assigned while building the macro.

 

The other option is to use the Capture Control command. The control information is captured during the playback of a macro. The information is taken from the control sitting underneath the mouse cursor at the time the command is run.

 

 

Manipulating the Variable

After the information has been saved to a Control type variable, there are a number of options available for using this information.

 

 

If Statements

Set up conditional If Control statements, such as if the Control is visible, has focus or is enabled. Or  base the statement on if the control is not visible, doesn't have focus or is disabled.

Mouse Click

Have the mouse click on the control at some point during the macro. This is a good way to make sure the correct button is pressed, the right edit field has focus, etc.

Set Focus

Set focus to the control during playback of the macro.

Set Control Text

This Set Control Text option defines the text for the control variable. This is helpful when the captured control is an edit box containing text.

Modify the Controls

The Variable Modify Controls options allow for copying the variable to another variable or to modify the top level window for more macro flexibility.

Post Message

The Post Message command allows the user to send a Windows message to a specific control.

Send Text Directly to a Control

The Text Type command includes a Send Text Directly to Control option. The text is inserted directly to the control (if the control selected accepts text input). The control must be running on the computer, but focus to the control is not required for the text to be inserted.

Wait for Control

Instruct a macro to wait for the control to gain focus, become visible or become enabled. Or cause the macro to wait for their opposites - wait for control to lose focus, become invisible or become disabled.

 

 

In summary, the controls open up many more possibilities for creating macros. Use them to more reliably work with Child Windows (windows within windows). Directly click on a button or go to a specific edit box without having to Tab through fields or position the mouse just right.

 

 

üNote: Not every button, menu item or component on a program is actually a Control. Sometimes the only control in a given program is the window or dialog that pops up when the program starts. How the controls work depends on how the application was written.