ctrx_execute_on_window_activation

ExampleGeneral Functions

Specifies handler function on window activation.

void ctrx_execute_on_window_activation( char *window_name, long handler );

window_nameThe name of the window that initiates the handler.
handlerThe function to invoke when the window is activated.

ctrx_execute_on_window_activation specifies the function to call when a window is brought into focus. When a window with the name window_name is activated, the handler function is invoked.

The asterisk wildcard character (*) can be used in window_name.

Put the actions you wish to perform in the handler function, which must have the following prototype:

int handler( char *title);

The name of the window is passed to the handler as title argument.

Note:  

  • We recommend including a think time after the handler function is invoked, especially if it is invoked at the end of the Actions section of a Vuser script. If the handler function is invoked at the end of the Actions section and is not followed by a think time, the vuser_end logoff procedure may be executed before the handler function is completed.
  • The lr_rendezvous function is not supported when a ctrx_execute_on_window_activation function is pending.

Return Values

This function has no return value.

Parameterization

No parameterization is available for this function.

Example

The following example creates a callback function that is triggered when the Notepad application is brought into focus. The callback message writes the name of the window in the log. This records how many times Notepad was brought into focus.

Copy code
int callbackf(char *title)
{
    lr_log_message("The following window just gained focus: %s", title);
    return 0;
}

Action()
{
  ctrx_execute_on_window_activation ("Untitled - Notepad", callbackf);

}