Address of FF routine

Started by John Montenigro, June 12, 2014, 05:34:59 PM

Previous topic - Next topic

John Montenigro

On my frmLogin, I've created a label (lblCountdown) and two timers (Timer1 and TimerCountdown)

Timer1 is set to 20 seconds, and once expired, closes the form. No problems.

The second timer is initialized for 1 second, and changes the number shown on the the label. Works fine.

But I also want the timer to restart when the user starts to type in txtUserName. I know that I have to kill the
Timer1 and create it anew, but I have a question about the syntax of the SetTimer command in FF. Please see below.

I don't know how to provide a pointer to the code. I've tried CodePtr, but that doesn't work.

What syntax should I be using?

Thanks,
-John


Function FRMLOGIN_TIMERCOUNTDOWN_WM_TIMER ( _
                                  hWndForm      As Dword, _  ' handle of Form
                                  wTimerID      As Dword  _  ' the timer identifier
                                  ) As Long
   Decr glCountdownCounter                                   
   FF_Control_SetText(HWND_FRMLOGIN_lblCountdown, Format$(glCountdownCounter, "00"))                                   
End Function

Function FRMLOGIN_TXTUSERNAME_EN_CHANGE ( _
                                        ControlIndex   As Long,  _  ' index in Control Array
                                        hWndForm       As Dword, _  ' handle of Form
                                        hWndControl    As Dword, _  ' handle of Control
                                        idTextControl  As Long   _  ' identifier of text control
                                        ) As Long
   'KillTimer hWndForm, wTimerID
   KillTimer HWND_FrmLogin, HWND_FrmLogin_TimerCountdown

   'SetTimer  hWndForm, wTimerID , NewInterval * 1000, ByVal %Null                                         
   SetTimer  HWND_FrmLogin, HWND_FrmLogin_TimerCountdown , 20 * 1000, ByVal CodePtr(FRMLOGIN_TIMERCOUNTDOWN_WM_TIMER)                                         
End Function


Petrus Vorster

I hope im not completely off the wagon here, but why not use only one timer?

Set if for 1 second intervals to change the label and set a LONG/INTEGER in that procedure to count +1 everytime the label is changed and close the form once you reach 20?

That is what i would do.
-Regards
Peter

David Kenny

#2
John,

There is no such thing as a timer control (at least as far as FF programming goes).  I've seen this type of mistake before and wrote a demo to help with understanding timers in FF.  See here: http://www.planetsquires.com/protect/forum/index.php?topic=3479.0

In reference to your question:
QuoteI have a question about the syntax of the SetTimer command in FF.
There is no SetTimer command in FF.  It is simply a Windows API routine and is documented in MSDN.

I have modified your code below (only the last line):
Function FRMLOGIN_TIMERCOUNTDOWN_WM_TIMER ( _
                                  hWndForm      As Dword, _  ' handle of Form
                                  wTimerID      As Dword  _  ' the timer identifier
                                  ) As Long
   Decr glCountdownCounter                                   
   FF_Control_SetText(HWND_FRMLOGIN_lblCountdown, Format$(glCountdownCounter, "00"))                                   
End Function

Function FRMLOGIN_TXTUSERNAME_EN_CHANGE ( _
                                        ControlIndex   As Long,  _  ' index in Control Array
                                        hWndForm       As Dword, _  ' handle of Form
                                        hWndControl    As Dword, _  ' handle of Control
                                        idTextControl  As Long   _  ' identifier of text control
                                        ) As Long
   'KillTimer hWndForm, wTimerID
   KillTimer HWND_FrmLogin, HWND_FrmLogin_TimerCountdown

   'SetTimer  hWndForm, wTimerID , NewInterval * 1000, ByVal %Null                                         
   SetTimer  HWND_FrmLogin, HWND_FrmLogin_TimerCountdown , 20 * 1000)    'Dropped the optional CodePtr                                   
End Function


The CodePtr option is to allow you to define your own handling routine.  If you don't specify one, it sends it to your applications message queue where internal FF code picks it out and redirects it to the routine you were trying to point to. 

David

Added:
BTW, the 'TimerProc callback function' you were pointing to with the CodePtr should have four arguments.  The FRMLOGIN_TIMERCOUNTDOWN_WM_TIMER routine in FF has only two.  That probably wouldn't end pretty.  ;)

John Montenigro

#3
Thanks for the help!
-John

@Peter,
I want the splash screen to close after 20 seconds of no activity.
But if the user types a key, the timer resets to 20.
The second timer is only for displaying the countdown.


@David,
OK, redesign in progress! (Not using the Code Pointer version!!)


P.S. I also found Rolf's Timer example code and snippets, so I think I've got it now!