Citrix ICA Vuser Functions (CTRX) > Alphabetical List of Functions > ctrx_execute_on_window

ctrx_execute_on_window

Example General Functions

Specifies handler function on window appearance.

void ctrx_execute_on_window( char *window_name, long handler );

window_name The name of the window that initiates the handler.
handler The function to invoke when the window is displayed.

ctrx_execute_on_window specifies the function to call when a window appears. When a window with name window_name appears, the handler function is invoked. ctrx_execute_on_window is typically used to handle a popup dialog box.

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: The lr_rendezvous function is not supported when a ctrx_execute_on_window function is pending.

Return Values

This function has no return value.

Parameterization

No parameterization is available for this function.

Example

This example shows the definition and use of an event handler function, close_unsaved_changes.

When exiting the Microsoft Word application with an open document containing unsaved changes, a Yes-No-Cancel message window with the title "Microsoft Word" appears prompting the user to save the document.

ctrx_execute_on_window specifies that when this dialog appears, the function close_unsaved_changes is invoked. This function tabs through to the dialog's "No" button and hits the "Enter" key, thereby exiting the application without saving.

int close_unsaved_changes(char win_title[]) {     /* Note: the parameter win_title is not used in the handler */
     ctrx_key("TAB_KEY", 0, CTRX_LAST); /* tab through to "No" button */
     ctrx_key("ENTER_KEY", 0, CTRX_LAST); /* hit the "No" button */

     return 0;
}

vuser_init () {

     /* If "Microsoft Word" popup appears then close it*/
     ctrx_execute_on_window("Microsoft Word", close_unsaved_changes);

     ctrx_set_connect_opt(APPLICATION, "#word");
     ctrx_set_connect_opt(NETWORK_PROTOCOL, "TCP/IP");
     ctrx_connect_server("ludens", "test", "test", "ludens");
     ctrx_wait_for_event("LOGON");
     ctrx_set_window("Document1 - Microsoft Word", CTRX_LAST);
     ctrx_type("This is a test", CTRX_LAST);
     lr_think_time(3);

     /* Close MS Word by clicking the X button of the title bar. This will cause
      * the "Microsoft Word" unsaved changes dialog window to appear */
     ctrx_mouse_click(28, 38, LEFT_BUTTON, 0, "Document1 - Microsoft Word", CTRX_LAST);
     lr_think_time(1);
     ctrx_mouse_click(43, 404, LEFT_BUTTON, 0, "Document1 - Microsoft Word", CTRX_LAST);
     lr_think_time(5);
     ctrx_disconnect_server("ludens", CTRX_LAST);

     return 0;
}