Skip to content

Implemented BindWinEvent for Windows Message events#196

Merged
DougHennig merged 5 commits into
DougHennig:masterfrom
JoelLeach:bindwinevent
Apr 13, 2021
Merged

Implemented BindWinEvent for Windows Message events#196
DougHennig merged 5 commits into
DougHennig:masterfrom
JoelLeach:bindwinevent

Conversation

@JoelLeach

Copy link
Copy Markdown

While using ProjectExplorer, I noticed that FoxTabs wasn't working right. I figured this probably came down to event binding conflicts, since FoxTabs makes heavy use of events. Years ago, I discovered the following statement in the VFP Help file:

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

Due to this limitation, Greg Green ran into conflicts between FoxTabs and his utilities. So, he developed a small framework to work around the limitation. It basically converts Win Msg events to standard VFP events, which allow multiple bindings. There is more on this subject at http://www.joelleach.net/2010/04/11/foxtabs-092-and-multiple-windows-event-bindings/.

I implemented this framework with ProjectExplorer, and I have been using it for a couple of months. It resolved the conflicts, and I have not noticed any ill effects. That said, you would want to confirm that your Win Msg event bindings are still working as expected. If you refactor any of the code, please ensure that the VFPxWin32EventHandler interface remains the same and that the instance is named "_Screen.oEventHandler", as FoxTabs and ProjectExplorer will be sharing that object.

This is my first pull request, so let me know if I did it wrong! :)

@DougHennig DougHennig merged commit e88f93c into DougHennig:master Apr 13, 2021
@DougHennig

Copy link
Copy Markdown
Owner

I found one issue: VFPxWin32EventHandler.CleanupEvents causes an error if there are no events, such as when closing Project Explorer without having edited anything. I changed:

If laWinEvents[lnRow,1] = loWinEvent.hWnd and laWinEvents[lnRow,2] = loWinEvent.nMessage

to:

If not empty(laWinEvents[lnRow,1]) and laWinEvents[lnRow,1] = loWinEvent.hWnd and ;
laWinEvents[lnRow,2] = loWinEvent.nMessage

@JoelLeach

Copy link
Copy Markdown
Author

I suppose that would never happen in FoxTabs, but I will make the change there too. Thanks!

@DougHennig

Copy link
Copy Markdown
Owner

I made a couple of other changes to support calling UnbindWinEvents with 2 parameters:

  • In UnbindWinEvents.prg, change:

CASE Pcount() = 3

to:

CASE Pcount() = 2

  • In VFPxWin32EventHandler.prg.UnBindEvents, I added another case:

CASE Pcount() = 2
* Unbind specific event/message
UnBindEvents(thWnd, tnMessage)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants