Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Timer enabled
Message
De
02/11/2012 10:47:09
 
 
À
01/11/2012 21:03:34
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01545860
Message ID:
01556321
Vues:
84
>This looks like an interesting class, but it has to live in a form, right, because of the reference to thisform.hWnd?
>
>I'd like to use it in an object with baseclass = Custom, no form involved.
>
>Is that possible?

The Win API requireds a valid handle -- you could try using _VFP.hWnd. Just replace the thisform with _VFP and I believe it should work. To be sure you have the most recent code version I have added it below. The Win32 API functions are defined in a global prg "library" file and are DECLARED using the AS syntax with the "api" added as a prefix:
FUNCTION apiSetTimer
	LPARAMETERS tnhWnd, tnIDEvent, tuElapse, tlpTimerFunc
	DECLARE LONG SetTimer IN User32 AS apiSetTimer LONG nhWnd, LONG nIDEvent, LONG uElapse, LONG pTimerFunc
	RETURN apiSetTimer(tnhWnd, tnIDEvent, tuElapse, tlpTimerFunc)
ENDFUNC
Current Class library
**************************************************
*-- Class Library:  e:\my work\foxpro\projects\gkktools\editors\classes\gkkapitimer.vcx
**************************************************


**************************************************
*-- Class:        apitimer (e:\my work\foxpro\projects\gkktools\editors\classes\gkkapitimer.vcx)
*-- ParentClass:  label
*-- BaseClass:    label
*-- Time Stamp:   08/12/12 02:42:05 PM
*
*-*
*-*	API Timer limits
*-*
#DEFINE USER_TIMER_MINIMUM      10
#DEFINE USER_TIMER_MAXIMUM      0x7FFFFFFF
*
DEFINE CLASS apitimer AS label


	AutoSize = .T.
	BackStyle = 0
	Caption = "apiTimer"
	Height = 17
	Visible = .F.
	Width = 51
	*-- Numeric Timer ID
	timerid = 0
	*-- XML Metadata for customizable properties
	_memberdata = [<VFPData><memberdata name="timerid" type="property" display="TimerID"/><memberdata name="hwnd" type="property" display="hWnd"/><memberdata name="interval" type="property" display="Interval"/><memberdata name="ontimerinterval" type="method" display="OnTimerInterval"/><memberdata name="initializetimer" type="method" display="InitializeTimer"/><memberdata name="cleartimer" type="method" display="ClearTimer"/><memberdata name="interval_assign" display="Interval_Assign"/><memberdata name="active" type="property" display="Active"/><memberdata name="active_assign" display="Active_Assign"/><memberdata name="destroy" display="Destroy"/><memberdata name="init" display="Init"/></VFPData>]
	*-- Handle to Timer
	hwnd = 0
	*-- Interval of timer; value assigned in seconds and displayed in milliseconds; default is 30min
	interval = 900000
	*-- Indicates that the timer is active
	active = .F.
	Name = "apitimer"


	*-- Occurs when the Timer interval completes
	PROCEDURE ontimerinterval
		LPARAMETERS thWnd, tnMsg, tnTimerID, tlParam
		IF this.hWnd = thWnd .AND. this.TimerID = tnTimerID

		ENDIF
		RETURN 0
	ENDPROC


	*-- Initializes the timer
	HIDDEN PROCEDURE initializetimer
		IF !PEMSTATUS(thisform,"apiTimerCount",5)
			ADDPROPERTY(thisform,"apiTimerCount",0)
		ENDIF
		IF this.Active
			thisform.apiTimerCount = thisform.apiTimerCount + 1
			BINDEVENT(this.hWnd, WM_TIMER, This, 'OnTimerInterval')
			apiSetTimer(this.hWnd, this.TimerID, this.Interval, 0)
		ENDIF
	ENDPROC


	*-- Clears the timer function
	HIDDEN PROCEDURE cleartimer
		apiKillTimer(this.hWnd, this.TimerID)
		IF PEMSTATUS(thisform,"apiTimerCount",5)
			thisform.apiTimerCount = thisform.apiTimerCount - 1
			IF thisform.apiTimerCount = 0
				UNBINDEVENTS(this.hWnd)
			ENDIF
		ENDIF
	ENDPROC


	HIDDEN PROCEDURE interval_assign
		LPARAMETERS tnInterval
		tnInterval = tnInterval * 1000     && Convert seconds to milli-seconds
		DO CASE
			CASE tnInterval < USER_TIMER_MINIMUM
				this.Interval = USER_TIMER_MINIMUM

			CASE tnInterval > USER_TIMER_MAXIMUM
				this.Interval = USER_TIMER_MAXIMUM

			OTHERWISE
				this.Interval = tnInterval
		ENDCASE
	ENDPROC


	HIDDEN PROCEDURE active_assign
		LPARAMETERS tlActive
		this.Active = tlActive
		IF tlActive
			this.InitializeTimer()
		ELSE
			this.ClearTimer()
		ENDIF
	ENDPROC


	PROTECTED PROCEDURE Init
		this.hWnd = thisform.hWnd
		this.Interval = this.Interval
	ENDPROC


	PROTECTED PROCEDURE Destroy
		this.ClearTimer()
	ENDPROC


ENDDEFINE
*
*-- EndDefine: apitimer
**************************************************
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform