Timer

Started by StefanMenner, April 24, 2004, 07:32:14 AM

Previous topic - Next topic

StefanMenner

Hi folks,

i am just playing with FF and am stuck right here:

The app's main form has a button to minimize to the system tray. This works.
A seperate thread is checking regularly for a condition to display another form.
I want this form to disappear after 5 secs so i inserted the following code to its WM_SIZE event:

LOCAL L AS LONG

ANIMATEWINDOW hWndForm, 100, %AW_HOR_POSITIVE OR %AW_SLIDE
L = SETTIMER(hWndForm, 1, %TIMERIntervall_Notify, BYVAL 0)
IF L = 0 THEN
MESSAGEBOX hWndForm, BYCOPY "Error creating Timer" & $CRLF, BYCOPY "ISDNNotify", %MB_ICONERROR OR %MB_APPLMODAL
END IF

This works fine, the form comes sliding in.
In the CUSTOM event i put in

SELECT CASE wMsg
  CASE %WM_Timer  
  ANIMATEWINDOW hWndForm, 100, %AW_HOR_NEGATIVE OR %AW_SLIDE OR %AW_HIDE
  KILLTIMER hWndForm, 1
END SELECT

But the form is never closing. Playing with MessageBox shows that WM_TIMER does not fire here.

Where is my fault :?:

Thanks,
Stefan

George Bleck

Try putting the below code into your custom msg area and remove the stuff in %WM_SIZE


  STATIC boolTimerStarted AS LONG
  SELECT CASE wMsg
     CASE %WM_TIMER
        ANIMATEWINDOW hWndForm, 100, %AW_HOR_NEGATIVE OR %AW_SLIDE OR %AW_HIDE
        KILLTIMER hWndForm, 1
        boolTimerStarted = %FALSE
     CASE %WM_ACTIVATE
        IF boolTimerStarted = %FALSE THEN
           LOCAL L AS LONG
           ANIMATEWINDOW hWndForm, 100, %AW_HOR_POSITIVE OR %AW_SLIDE
           L = SETTIMER( hWndForm, 1, %TIMERIntervall_Notify, BYVAL 0 )
           IF L = 0 THEN
              MESSAGEBOX hWndForm, BYCOPY "Error creating Timer" & $CRLF, BYCOPY "ISDNNotify", %MB_ICONERROR OR %MB_APPLMODAL
              boolTimerStarted = %TRUE
           END IF
        END IF
  END SELECT

StefanMenner

Thank you George, but i'm afraid that didn't help (although it looks OK to me).

Seems like the Function FRMmyForm_CUSTOM is never entered?!?
Any ideas?
Maybe Paul knews a way to check this?

Stefan

TechSupport

Hi Stefan,

I think that George is pointing you in the right direction. Using the boolTimerStarted flag ensures that you do not have multiple timers created concurrently.

Also, using the WM_ACTIVATE is better than WM_SIZE.

Lastly, is your constant %TIMERIntervall_Notify defined as milliseconds instead of seconds (ie. 5 seconds being 5000 milliseconds).

TechSupport

Quote from: StefanMennerThank you George, but i'm afraid that didn't help (although it looks OK to me).

Seems like the Function FRMmyForm_CUSTOM is never entered?!?
Any ideas?
Maybe Paul knews a way to check this?

Stefan

Hmmm... hard to tell. Maybe a thread issue???? Not sure.

I created a sample Form with one CommandButton on it. When I clicked that button it showed a second Form. In the second Form I created a timer in WM_NCACTIVATE and then killed it in WM_CUSTOM and then FF_CloseForm after the kill - and everything worked okay.

There must be something else happening in your code. Are you sure that your are setting the timer and checking for WM_TIMER in the CUSTOM message of the correct Form. FRMmyForm is your popup Form right?

Are you destroying the second Form at some point in your code??? You should call FF_CloseForm in the WM_TIMER code of your CUSTOM message for the second form.

If you would like you can email me the files and I can test it here.

StefanMenner

Thank you Paul, the mail just left my PC.
Stefan

TechSupport

Thanks Stefan, I received your files and have sent you back an email.

It appears that the problem was that the second Form was being displayed from a different thread. This presents a problem because the message pump is in the main thread. In the thread, I simply used a user defined message that called the main window to tell it to show the second Form.

It appears to work okay. I expect that Stefan will test it further and report back if it does not work or if there are other problems.

StefanMenner

Indeed Paul. With your correction it works like a charm.

And - as usual - your support was / is excellent.

Thanks,
Stefan