SendMessage Command

Purpose

Sends a message to one or more windows. The SendMessage command does not return before the message has been processed. After receiving a SendMessage call Windows immediately calls the relevant window function.

Syntax

SendMessage hWnd, Mess, wParam, lParam [,RetVal]

RetVal = SendMessage(hWnd, Mess, wParam, lParam)

hWnd, Mess, wParam, lParam, RetVal: integer expressions

Description

Windows uses messages to communicate between different parts of a program and/or different programs. They either contain the information about the current operation of the program or pass information from other applications. Such messages are managed by Windows in a buffer which is called the message queue.

The SendMessage command contains four parameters. The first parameter (hWnd) specifies the window handle to be included in the message or, if a GFA-BASIC window, the GFA-BASIC 32 window number. If hWnd contains HWND_BROADCAST the message is posted to all overlapping windows in the system.

The second parameter (Mess) contains the message (for example WM_SYSKEYUP). The two last parameters contain additional message information. The first one (wParam) is an unsigned 32 bit value, the second (lParam) an unsigned 32 bit value. The final parameter [RetVal] is an optional return value coming from the window that the send message was addressed to.

For example, in case of WM_SYSKEYUP wParam contains the virtual key code and lParam the scan code, repeat counter, the original keyboard state and other additional information (for example whether the key is a function key). The message sent with the SendMessage command is processed immediately and is not posted in the message queue.

SendMessage command is processed instantly and is not put in the message queue.

Example

// activate the Help mode, simulates a press

// on the Help [?]-button

OpenW 1

CenterMouse Win_1

SendMessage Me.hWnd, WM_SYSCOMMAND, SC_CONTEXTHELP, 0

Do

Sleep

Until Me Is Nothing

Remarks

The GFA-BASIC command SendMessage corresponds to Windows function call SendMessage().

See Also

PostMessage

{Created by Sjouke Hamstra; Last updated: 23/10/2014 by James Gaite}