Using an event name with a PowerBuilder event ID
A simpler way to trigger events in
a visual extension uses direct mapping of Windows messages to PowerBuilder
events. The following class description contains the same two events,
but in this case they use the alternative syntax that maps the event
name to a PowerBuilder token name:
PBXEXPORT LPCTSTR PBXCALL PBX_GetDescription()
{
static const TCHAR desc[] = {
"class visualext from userobject\n"
"event onclick pbm_lbuttonup\n"
"event ondoubleclick pbm_lbuttondblclk\n"
"subroutine setcolor(int r, int g, int b)\n"
"subroutine settext(string txt)\n"
"end class\n"
};
return desc;
}
Generating event syntax automatically
Importing the extension generates the Onclick and Ondoubleclick
events with the appropriate arguments automatically, and at runtime,
the PBVM fires the events. You do not need to capture the Windows
messages WM_LBUTTONUP and WM_LBUTTONDBLCLK in
the extension.
In the following description, onclick is
the event name and pbm_lbuttonup is the
event token name. Notice that the event name is not followed by
empty parentheses as it is when you use the return type and arguments
technique for describing the event:
"event onclick pbm_lbuttonup\n"
About the token name
The token name is a string that maps to an internal PowerBuilder
event ID defined in the header file pbevtid.h.
The first ID in this file is PB_NULL.
For all other IDs in the file, there is a fixed relationship between
the name that you use in the description and the event ID in pbevtid.h.
The name is the same as the ID with the letter m appended
to the pb prefix. You must use lowercase in
the description.
For example, the event ID PB_ACTIVATE in pbevtid.h maps
to the token name pbm_activate. In
the description provided with PBX_GetDescription,
you must use the name pbm_activate.
If the event name you provide does not exist, importing the extension
generates an error message. See the pbevtid.h file
for a complete list of mapped IDs.