BindEvent() and Compile
* Window messaging constants
#define GWL_WNDPROC (-4)
#define WM_CREATE 0x0001
#define WM_DESTROY 0x0002
#define WM_SETTEXT 0x000C
* Create an instance of the wnHandler class
Public wmHandler As wmHandler
wmHandler = NewObject("wmHandler")
* Bind to all window create notifications
BindEvent(0, WM_CREATE, wmHandler, "wmEventHandler")
Return
* Define Windows messages event handler class
Define Class wmHandler As Custom
PrevWndFunc = 0
IgnoreEvents = .F.
Function wmEventHandler(hWnd As Integer, Msg As Integer, wParam As Integer, lParam As Integer)
Local lnReturn As Integer
Do Case
Case This.IgnoreEvents
? "Ignoring WM events"
Case Msg = WM_CREATE
? Transform(hWnd, "@0x"), "WM_CREATE", Transform(wParam, "@0x"), Transform(lParam, "@0x")
* Bind to the WM_SETTEXT messages received by this window
BindEvent(hWnd, WM_SETTEXT, wmHandler, "wmEventHandler")
Case Msg = WM_SETTEXT
? Transform(hWnd, "@0x"), "WM_SETTEXT", Transform(wParam, "@0x"), Transform(lParam, "@0x")
Case Msg = WM_DESTROY
* Remove all WM event bindings to this window
UnBindEvents(hWnd)
EndCase
* Pass the WM event to the intended Window procedure
lnReturn = CallWindowProc(This.PrevWndFunc, hWnd, Msg, wParam, lParam)
Return lnReturn
EndFunc
Function Init()
* Declare Win32 API functions
Declare Integer CallWindowProc In Win32API Integer lpPrevWndFunc, Integer hWnd, Integer Msg, Integer wParam, Integer lParam
Declare Integer GetWindowLong In Win32API Integer hWnd, Integer nIndex
* Store handle for use in CallWindowProc
This.PrevWndFunc = GetWindowLong(_Vfp.hWnd, GWL_WNDPROC)
EndFunc
Function Destroy()
* Remove all WM event bindings
UnBindEvents(0)
EndFunc
EndDefine

2 Comments:
Hi Scott,
Over on my blog I have an FLL that will allow you to do this and much more using a CBT hook. In any event, it could be used to solve your problem if Calvin doesn't come through for you and you don't mind an FLL dependency. Here's the link...
http://www.sweetpotatosoftware.com/SPSBlog/CommentView,guid,f7644db8-b155-4d43-8216-4cfde233edb7.aspx
By
Craig Boyd, at November 25, 2005 11:01 pm
Sorry to hear that I'm causing others to lose sleep.
++Alan
By
++Alan, at November 28, 2005 6:01 am
Post a Comment
<< Home