Purpose
Detours the events of a window or control to the method of another object.
Type
Function
Syntax
bRegisterByEventHandler(
<oWindow>,
<oMethodOwner>,
<symMethod>
) Æ lSuccess
Arguments
<oWindow> | The window or control, by which the events is to be detoured. |
Data type: | Object |
<oMethodOwner> | The object to which the events is to be detoured. |
Data type: | Object |
<symMethod> | The name of the method that is to be called in <oMethodOwner> and in which the detoured events is processed. |
Data type: | Symbol |
Return Value
lSuccess | A logical value that indicates whether the detour was activated. |
TRUE | The detour was activated. |
FALSE | The detour could not be activated. |
Data type: | Logic |
Description
The classes Window and control of CA-Visual Objects possess a general EventHandler that is called whenever Microsoft Windows sends a message (event) to the Window/Control. This EventHandler is implemented by the method Dispatch() and ensures for the fact that the arriving events is passed on or processed to subordinated EventHandler. Unfortunately not all messages of Microsoft Windows arrive in the method Dispatch(). Some are intercepted already before, by the class library, and are not passed on. In some cases one would like to react however nevertheless to this messages or another object is to the messages to react. For exactly these tasks the function bRegisterByEventHandler() serves. It detours the messages for a Window/Control to another object over before the method Dispatch() of the Window/Control is called. Thus the object receives the possibility to process the message. The method <symMethod> in the object <oMethodOwner> must have the following format:
<symMethod>(oEvent) class <classname>
If the method the arriving message to be processed or the message is not to be passed on to the window/control, the method must return the value NIL. Otherwise the value must be returned that is defined for the appropriate message. Which values that are, can be determined by the SDK of Microsoft Windows.
The function bRegisterByEventHandler() can be detoured also for a Window/Control on different objects. In this case the methods are called in the order in which they were registered by the function. As soon as a method returns a value unequally to NIL, the following registered methods are not called any longer.
Samples
The following sample detours the messages of a bBrowser on the method BrowserEventHandler() in its owner. In the method the KEYDOWN events are intercepted and a message is shown if the key RETURN were pressed. So that the events are passed on to the bBrowser, the method returns always the value NIL.
CLASS dtwSample INHERIT DataWindow
PROTECT oBrowser AS bBrowser
METHOD Init(oOwner) CLASS dtwSample
SUPER:Init(oOwner)
oBrowser := bBrowser{oOwner,;
1000,;
Point{0, 0},;
Dimension{300, 250}}
SELF:oBrowser:Show()
// detours the events of the bBrowser on the window
bRegisterByEventHandler(SELF:oBrowser,;
SELF,;
#BrowserEventHandler)
METHOD Destroy() CLASS dtwSample
// unregister the detour
bUnregisterByEventHandler(SELF:oBrowser, SELF)
RETURN SUPER:Destroy()
METHOD BrowserEventHandler(oEvent) CLASS dtwSample
// in this method all events of the bBrowser arrives
IF oEvent:uMsg=WM_KEYDOWN
IF InList(oEvent:WParam, KEYRETURN, KEYENTER)
MessageBox(SELF:Handle(),;
"RETURN key was pressed.",;
"Info",;
MB_OK+MB_ICONINFORMATION)
ENDIF
ENDIF
RETURN NIL
See Also
Page url: http://www.YOURSERVER.com/index.html?bregisterbyeventhandler.htm