Chapter 5. Controls related functions

This chapter describes functions used for manipulating several types of controls

This chapter is organized control-wise, since in most cases you will have a control and then you will look in the documentation in order to find out what can you do about them/how can you do what you want

In general you can classify all controls in 2 groups:

  • Common controls - they are provided by Microsoft for a long time and you may think of them as a part of operating system. The most important thing is that SendMessage handles all the necessary marshalling for you (don't worry if it does not tell you anything. I will explain it later)

  • Advanced controls and controls provided by other vendors - these are provided by Microsoft and other vendors. The most important differentiator between these and common controls is this marshalling thing

So what is marshalling all about?

In order to understand the issue, you need some background. Don't worry it won't hurt :), even if you are not an experienced Win32 programmer.

The most common mean of communicating with windows (i.e. controls, since they are windows, too) is by messages. If you want to add an item to a list control, you have to send it a message saying "please add this item to your list". To be more specific, you do it by calling SendMessage function. It has 4 parameters. First one is a handle to a window you want to communicate. Second one is message id - a command you want to send (add an item to a list) and the third and fourth one should contain additional parameters like a pointer to an item (string). The problem is, that if you issue this command from a script, which tests the application hosting this control, you are actually making interprocess call (script is one process, tested application - another one). The pointer to an item is valid only in address space of the test script. It will be invalid pointer in address space of tested application. This is where marshalling comes to the rescue. Marshalling is a trick (there are few kinds of tricks) which allows processes to exchange pointers and data. For common controls, Win32 do marshalling for you. It checks the command parameter in SendMessage and if it recognizes a command related to one of its basic controls, it does the marshalling for you. If you deal with other controls (not common) you have to take care about marshalling yourself. For more detailed description on what is marshalling and how it affects the code see the advanced tutorial.

There are 3 ways (which I know) of doing marshalling:

  • API hooking - you may intercept calls to some functions and make other process to call your function, in its address space (am I right? I have to double check)

  • DLL injection - you may force other process to run a dll provided by you in its address space

  • Using VirtualAllocEx function - this function allows to allocate memory in other process address space. You can send a pointer returned by VirtualAllocEx to this process and it will be able to safely use it

Currently in Win32::GuiTest marshalling for custom controls is done by API hooking. Although it works, I believe using VirtualAllocEx related method provides bigger flexibility. Have a look at the advanced tutorial to see VirtualAllocEx at work.

This sections contains functions, which perform operations common for controls


Enables or disables mouse and keyboard input to the specified window or control.


Returns the caret's position in client coordinates.


Retrieves the handle to the window that has the keyboard focus and is attached to a thread, which owns window specified as an input parameter


Retrieves the text associated with the control (for example edited text from EditBox)


Sets the text associated with the control (for example edited text in EditBox)