FoxTabs 0.9.2 and Multiple Windows Event Bindings

I know… I’ve been seriously neglecting my FoxTabs duties… again.  After a long delay, FoxTabs 0.9.2 has just been released.  There have only been a few issues since the last release over a year ago.  Unless new issues are introduced in this version (very possible), I expect this version will become a release candidate, and then version 1.0.

One of the reasons for the delay was an issue discovered by Greg Green, and I wasn’t sure of the best way to handle it.  Greg has created several replacements for the standard VFP editors and designers.  (If you are interested in Greg’s work, go to the Universal Thread Downloads page and enter GKK in the Search field.)  FoxTabs and Greg’s editors were conflicting with each other.  We were eventually led to this statement in the VFP Help for BindEvent():

When binding to Windows message (Win Msg) events, only one hWnd to Windows message pairing can exist.

Greg and I were trying to bind to the same Windows events, but “there can be only one”, so we were stepping on each other’s bindings.  Greg developed a small framework to work around the limitation, and I made some modifications to that for the latest FoxTabs release.

VFP does support multiple bindings for standard FoxPro events.  The solution we came up with adds an object to a collection for each Windows event and binds to that event, effectively translating the Win Msg to a standard Fox event.  BindEvent() is called again to bind the collection object to the intended event handler/delegate. This design allows as many bindings as you want.  The code includes two functions: BindWinEvent() and UnBindWinEvents().

BindWinEvent() has the same interface as the standard BindEvent() function:

BindWinEvent(hWnd | 0, nMessage, oEventHandler, cDelegate [, nFlags])

UnBindEvents() is similar to the standard UnBindEvents() function, but adds a couple of parameters.  Since multiple bindings are now possible, you have to specify which event handler/delegate you want to unbind:

UnBindWinEvents(hWnd | 0, nMessage | 0, oEventHandler, cDelegate)

You can pass 0 to nMessage if you want to unbind all the messages for a hWnd, such as when a window is closed/destroyed.  The following syntax is also supported if you want to unbind all events from an event handler object:

UnBindWinEvents(oEventHandler)

Clear as mud?  The bottom line is that it is recommended you use these functions instead of the standard VFP functions when binding to Windows events.  If everyone does that, then we won’t step on each others toes.  Unfortunately, that is a requirement.  There is nothing we can do to prevent another program from taking over your events with the standard VFP functions.

The code is included in FoxTabs 0.9.2 and is attached.  If you find any problems, please let me know.

Leave a Reply

Your email address will not be published. Required fields are marked *