SendMessage function in RoutineBot

The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.
Syntax

SendMessage( Handles:String, Message:String, WParam:Integer [optional], LParam:Integer [optional], Count:Integer [optional] )

Parameters

Handles:String

String that contains handles whose window procedure will receive the message. You can obtain these handles via function FindWindows.

Message:String

Specifies the message to be sent. If message is a number then this function is equivalent to WinAPI function SendMessage. Otherwise, can be one of predefined string constant

“Activate” – function activates windows with handles represented in parameter handles
“Close” – function closes windows with handles represented in parameter handles
“Maximize” – function maximizes windows with handles represented in parameter handles
“Minimize” – function minimizes windows with handles represented in parameter handles
“Normalize” – function normalizes windows with handles represented in parameter handles

WParam:Integer [optional]

Specifies additional message-specific information.

LParam:Integer [optional]

Specifies additional message-specific information.

Count:Integer [optional]

Specifies how many handles from parameter handle will be used in function. If this parameter is -1 then all handles will be used, otherwise function uses only first count handles form parameter handles.

Example

This Example will run Notepad.exe, type “abc”, save file and close Notepad.

SetWarningsOn('ON');
FilePath := 'c:\temp.txt';
FExist := FileExists(FilePath);
Execute('c:\windows\notepad.exe',FilePath);
//Running notepad
handles := FindWindows('','notepad');
//searching it handles
if ListSize(handles) > 0 then // if more than 1 window found
begin
h := ListItem(Handles,0);
SendMessage(h,'Activate'); //activating window
if not (FExist = 1) then
begin //if not exist file 'c:\temp.txt'
//we must enter button on keyboard
EnterKeys('{ENTER}');
handles := FindWindows('','notepad');
h := ListItem(Handles,0);
SendMessage(h,'Activate');
//searching and activating new notepad windows
end;
//maximizes window
SendMessage(h,'Maximize');
//typing text "abc"
EnterKeys('abc');
//typing Ctrl+S
EnterKeys('^s');
Wait(1000);
//Closing window. 16 is predefined constant
//for message WM_CLOSE
SendMessage(h,16);
end;

Download example SendMessage.

Posted in Articles
Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Example: GUI test with RoutineBot

RoutineBot is testing GUI, trying to enter various values into the text fields and processing warning messages that tested program shows.

Gui Test Automation

GUI Testing TipsCheck out our GUI Test Automation tips.
Test Automation Step-by-Step
Learn more than 99% users know about test automation! Subscribe to maillist now! Learn how to create scripts that will do routine job for you.

Email: