CONTROL SEND statement

Purpose | Send a message to a control.
Syntax | CONTROL SEND hDlg, id&, Msg&, wParam&, lParam& [TO lResult&]

Remarks

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 send 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 return or alter the values passed in the wParam& and lParam& parameters, pass them using VARPTR or the return values will be discarded. For example:

' Retrieve an Edit control's Current Selection

CONTROL SEND CB.HNDL, %ID_EDIT1, %EM_GETSEL, VARPTR(Sel1&), VARPTR(Sel2&)

CONTROL SEND does not return from execution until the control's callback has processed the message. This synchronous behavior is quite different to the behavior of CONTROL POST, which simply places the message in the control's message queue (for processing at a later time) and immediately returns. On this basis, CONTROL SEND can receive a return value from the message, but CONTROL POST cannot.

TO | The return value from the message can optionally be assigned to lResult&. If CONTROL SEND sends a message that arrives back in the same callback as the message originated, care should be exercised to ensure that critical STATIC and GLOBAL variables are not unexpectedly altered by the second message processing code in the callback. This is known as re-entrant code design.
Restrictions | To send a custom message to a dialog, 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 POST, DIALOG POST, DIALOG SEND
Example | ' Programmatically click a button: CONTROL SEND hDlg, %ID_BTN1, %BM_CLICK, 0, 0