PostMessage Command

Purpose

Posts a message to the message queue of an application program (window). The function does not wait (like SendMessage) for the message to be processed. The posted message is retrieved by calling the Windows functions GetMessage() or PeekMessage().

Syntax

PostMessage hWnd, Msg, wParam, lParam

hWnd, Msg, wParam, lParam:integer expression

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 PostMessage command contains four parameters. The first parameter (hWnd) specifies the window handle to be included in the message. If hWnd = HWND_BROADCAST ($FFFF) the message is posted to all overlapping windows in the system. The second parameter (Msg) contains the message (for example WM_SYSKEYUP). The two last 32-bit parameters wParam and lParam contain additional message information.

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 PostMessage command is posted in the message buffer (Queue) of the application (window) specified in hWnd and is not processed immediately (as is the case for SendMessage).

Example

OpenW # 1, 100, 100, 200, 200, ~15

DefFill 5

PRBox 0, 0, _X, _Y

Do

Sleep

Until Me Is Nothing

 

Sub Win_1_KeyPress(Ascii&)

PostMessage Me.hWnd, WM_CLOSE, 0, 0

EndSub

Remarks

The GFA-BASIC command PostMessage corresponds to built-in Windows function call PostMessage().

See Also

SendMessage

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