The API function SetTimer

Started by Stephane Fonteyne, January 14, 2010, 07:52:24 AM

Previous topic - Next topic

Stephane Fonteyne

hello support,

we wanted to know in witch conditions in a project we can use the api function SetTimer with parameter TimerProc.

we like to have a little example about this topic.


private sub Timer1_Timer()
->Vb statement

we want to know the equivalent of this Vb6 function( the code ) in Firefly
sdk designer.

we think that it could be WM_TIMER, but we're not sure about that.
Our question is now tjhe difference between TimerProc and WM_TIMER, when do we have to use it etc...

We are confident that we can get soon an answer from you

greetings
Stefaan

Stephane Fonteyne
Ba. Elektronica - ICT
GSM : +32-xxxxxxxxxx
PowerBasic Developer & Hardware Support

Eddy Van Esch

#1
You can use SetTimer with a WM_TIMER message in DlgProc, but I find it more comfortable to use a direct link to the timer handler function or sub.
Like this:

ghTimer = SETTIMER(hDlg, BYVAL 1, 1000, CODEPTR(MyTimerProc))  'Timer ID is 1, time-out is 1000 ms
...
SUB MyTimerProc(BYVAL hWnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL IDEvent AS DWORD, BYVAL dwTime AS DWORD)   
   LOCAL i as LONG

           'If this sub is being executed, it means that this timer has timed out.
           'Kill the timer. [b]IF[/b] It is not needed anymore. Otherwise, this sub will keep getting called.
    i = KILLTIMER(hDlg, BYVAL 1)
    ...
END SUB
Eddy

Paul Squires

#2
Quote from: Stephane Fonteyne on January 14, 2010, 07:52:24 AM
hello support,

we wanted to know in witch conditions in a project we can use the api function SetTimer with parameter TimerProc.

we like to have a little example about this topic.


private sub Timer1_Timer()
->Vb statement

we want to know the equivalent of this Vb6 function( the code ) in Firefly
sdk designer.

we think that it could be WM_TIMER, but we're not sure about that.
Our question is now tjhe difference between TimerProc and WM_TIMER, when do we have to use it etc...

We are confident that we can get soon an answer from you

greetings
Stefaan


Who are the "we" that you are referring to?

The use of a Timer is a Windows concept, not a FireFly concept. I trust that you have already read the extensive documentation already available for Timers? Try this page for starters: http://msdn.microsoft.com/en-us/library/ms632592(VS.85).aspx

The SetTimer api function allows the programmer to direct the timer message to the form's WM_TIMER handler -or- to a user defined function (in the format described by Eddy in his above post). Please read the documentation for SetTimer located here: http://msdn.microsoft.com/en-us/library/ms644906(VS.85).aspx


Paul Squires
PlanetSquires Software

Roger Garstang

Quote from: TechSupport on January 14, 2010, 10:35:34 AM
Who are the "we" that you are referring to?

It is what I wondered all along...Stephane is really Borg trying to add our biological and technological distinctiveness to their own with all his open questions. We are Stephane...resistance is futile!

P.S.  His last two posts he uses We.  I was asking myself the same questions when reading them.

Stephane Fonteyne

Hi all,

The "we" is I and my neightbour student that developed this small projects but he doesn't an little experience in WinAPI

Stephane
Stephane Fonteyne
Ba. Elektronica - ICT
GSM : +32-xxxxxxxxxx
PowerBasic Developer & Hardware Support

Roger Garstang

WinAPI is tricky to grasp coming from VB, especially if VB or Visual Studio is the only thing you've known.  Luckily I came from TRS-DOS/TRS-BASIC/Assembly/Pascal/Ada/Cobol/GW-BASIC/BASICA/QandQuick BASIC/PB-DOS/C/C++/VB6/PBWin/VS2005/VS2008/etc, so it wasn't much to understand it.  If you haven't already, Petzold's Win32 Book and Rector & Newcomer's book are a good start to get out of the Visual Studio mindset. PB's site has the Win32 API help you can download too.  I found the 24MB version somewhere and a bunch of other chm/hlp files on some of the other APIs as well, but I use the basic 24MB one the most with an occasional glance at MSDN to make sure something didn't change in Win2k/XP/Vista/7.