Sending Windows messages
To send Windows messages to a window that you created in PowerBuilder or to
an external window (such as a window you created using an external function),
use the Post or Send function. To trigger a PowerBuilder event, use the
EVENT syntax or the TriggerEvent or PostEvent function.
Using Post and Send
You usually use the Post and Send functions to trigger Windows
events that are not PowerBuilder-defined events. You can include these
functions in a script for the window in which the event will be
triggered or in any script in the application.
On UNIX On UNIX, support for Windows messages is provided by the Wind/U
layer of PowerBuilder. However, you should avoid using the PowerScript
Post and Send functions to send messages in a UNIX application because
they require you to specify explicit message numbers (which can
change).
PowerBuilder does not support any native UNIX signal handling
or interprocess or interclient communications.
Post is asynchronous: the message is posted to the message
queue for the window or control. Send is synchronous: the window
or control receives the message immediately.
As of PowerBuilder 6.0, all events posted by PowerBuilder are
processed by a separate queue from the Windows system queue. PowerBuilder posted messages
are processed before Windows posted messages.
Obtaining the window’s handle To obtain the handle of the window, use the Handle function.
To combine two integers to form the long value of the message, use
the Long function. Handle and Long are utility functions, which
are discussed later in this chapter.
Triggering PowerBuilder events
To trigger a PowerBuilder event you can use:
Technique | Description |
---|---|
TriggerEvent function | A synchronous function that triggers the event immediately in the window or control |
PostEvent function | An asynchronous function: the event is posted to the event queue for the window or control |
Event call syntax | A method of calling events directly for a control using dot notation |
All three methods bypass the messaging queue and are easier
to code than the Send and Post functions.
Example All three statements shown below click the CommandButton cb_OK
and are in scripts for the window that contains cb_OK.
The Send function uses the Handle utility function to obtain
the handle of the window that contains cb_OK, then uses
the Long function to combine the handle of cb_OK with 0
(BN_CLICK) to form a long that identifies the object and
the event:
1 |
Send(Handle(Parent),273,0,Long(Handle(cb_OK),0)) |
1 |
cb_OK.TriggerEvent(Clicked!) |
1 |
cb_OK.EVENT Clicked() |
The TriggerEvent function identifies the object in which the
event will be triggered and then uses the enumerated data type Clicked!
to specify the clicked event.
The dot notation uses the EVENT keyword to trigger the Clicked
event. TRIGGER is the default when you call an event. If you were
posting the clicked event, you would use the POST keyword:
1 |
Cb_OK.EVENT POST Clicked() |