CONTROL POST statement

Purpose

Place a message in the message queue to be processed at the leisure of the target control.

Syntax

CONTROL POST hDlg, id&, Msg&, wParam&, lParam&

Remarks

CONTROL POST places the message in the message queue and returns immediately. The message is processed by the control at a later time, when it reads the message from the queue.

This behavior is quite different to the CONTROL SEND statement, which forces the control to process the message immediately before returning. Since CONTROL POST is an asynchronous operation, it is not possible to retrieve a return code from the message.

hDlg refers to the dialog that owns the control.

id& is the unique control identifier as assigned to the control with a CONTROL ADD statement.

Msg& is the message you want to post to the control.

wParam& is the first message parameter. lParam& is the second message parameter. The values of wParam& and lParam& are message-dependent. By Default, PowerBASIC passes these parameters BYVAL. If the target control is expected to alter the values held by variables passed in the wParam& and lParam& parameters, pass them using VARPTR() or the changes will likely be discarded.

Note that the address of the data must remain valid until after the control has processed the message and accessed the data. In this case, using STATIC or GLOBAL variables can be very important or a General Protection Fault (GPF) may occur (that is, if the variables have gone out of scope by the time the message is processed).

An example of posting the addresses of variables to a control:

' Retrieve an Edit controls Current Selection

' Sel1& and Sel2& must be STATIC or GLOBAL

CONTROL POST CB.HNDL, %ID_EDIT6, %EM_GETSEL, VARPTR(Sel1&), VARPTR(Sel2&)

CONTROL POST returns immediately after the placing the message in the queue.

Restrictions

To post a custom message to a control, use a message value in the range of (%WM_USER + 500) to (%WM_USER + &H07FFF), or use the RegisterWindowMessage API to obtain a unique message value from the operating system. Using messages with a numeric value of less then %WM_USER + 500 may conflict with Windows Common Control messages.

See also

Dynamic Dialog Tools, CONTROL HANDLE, CONTROL SEND, DIALOG POST, DIALOG SEND

Example

' Programmatically post a click message to a button:

CONTROL POST hDlg, %ID_BTN1, %BM_CLICK, 0, 0