Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Windows Event Binding
Message
De
30/12/2004 22:30:12
John Onysko
1 Edi Source, Inc.
Hudson, Ohio, États-Unis
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Windows Event Binding
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
00973481
Message ID:
00973481
Vues:
81
I have a base class status bar that is used in several of my applications to display misc. data (by the way, I used to bind it's location to _Screen.Resize, but the new Anchor property works great with _Screen). Anyway, one thing that I've never been able to do nicely is to have a CAPS and NUM indicator. The problem was that a timer was needed to continuously poll CAPSLOCK() and NUMLOCK(). I was really excited to start playing with Windows Event Binding in VFP9. Alas, after a few hours of trying different approaches I couldn't figure it out. I then ripped open my newest issue of FoxTalk and voila -- front page news -- "Windows Event Binding Made Easy" by Doug Hennig.

10 minutes later I had a starting point and about 30 minutes after that the finished product. It was so easy that my mind was over-complicating it. Thanks for the enlightenment Doug.

Doug's examples were great, but I needed an offshoot that was even more simple. The few lines of code at the end of this post take care of my needs nicely! Simply add BINDEVENTs and a corresponding "CASE" to do anything with any windows event that you need. I hope the example comes in handy to anyone trying to figure out how to bind to windows events.
**  12/29/2004
**  THIS IS THE PRIMARY EVENT HANDLER ROUTINE

**  DO NOT RUN IF THE EVENT HANDLER IS ALREADY INSTANTIATED (THIS REALLY SHOULDN'T HAPPEN)
IF TYPE("oEventHandler") = "O"
	RETURN
ENDIF

**  INCLUDE WINEVENTS.H
#INCLUDE WinEvents.H

**  CREATE THE PRIMARY EVENT HANDLER CLASS
PUBLIC oEventHandler
oEventHandler = CREATEOBJECT("EventHandler")

**  BIND THE EVENTS THAT WE NEED TO
BINDEVENT(_VFP.hWnd, WM_KEYUP, oEventHandler, "Eventhandler")
BINDEVENT(_VFP.hWnd, WM_ACTIVATE, oEventHandler, "Eventhandler")

**  END
DEFINE CLASS EventHandler AS Custom

nOldProc = 0

	FUNCTION Init
		DECLARE INTEGER GetWindowLong IN Win32API ;
			INTEGER HWND, INTEGER nIndex
		DECLARE INTEGER CallWindowProc IN Win32API ;
			INTEGER lpPrevWndFunc, INTEGER HWND, INTEGER Msg, INTEGER wParam, ;
			INTEGER LPARAM
		DECLARE INTEGER FindWindowEx IN Win32API;
			INTEGER, INTEGER, STRING, STRING
		DECLARE INTEGER GetWindowText IN Win32API ;
			INTEGER, STRING @, INTEGER
		THIS.nOldProc = GetWindowLong(_SCREEN.HWND, GWL_WNDPROC)
	ENDFUNC
	
	FUNCTION EventHandler(hWnd, Msg, wParam, lParam)
		DO CASE
			**  WINDOW ACTIVATE
			CASE Msg = WM_ACTIVATE
				**  THE STATUS BAR DOES NOT UPDATE WHEN VFP DOES NOT HAVE FOCUS
				**  THIS CAUSES THE STATUS BAR TO REFRESH UPON WINDOW ACTIVATION
				IF TYPE("_Screen.Status_Bar") = "O"
					_Screen.Status_Bar.Refresh_Data
				ENDIF

			**  KEYPRESS RELEASE
			CASE Msg = WM_KEYUP
				DO CASE
					**  CAPSLOCK & NUMLOCK
					CASE wParam = 20 OR wParam = 144
						IF TYPE("_Screen.Status_Bar") = "O"
							_Screen.Status_Bar.Refresh_Data
						ENDIF
				ENDCASE
		ENDCASE

		**  PRIMARY RETURN -- THIS NEEDS TO BE HERE OR THE WINDOWS EVENT WILL BE TRAPPED
		**  THIS IS THE EQUIVALENT OF DODEFAULT IN FOXPRO
		RETURN CallWindowProc(This.nOldProc, hWnd, Msg, wParam, lParam)
	ENDFUNC
ENDDEFINE
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform