PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Modal Form Question  (Read 468 times)

RhodyRich

  • Guest
Modal Form Question
« on: December 28, 2008, 12:20:07 PM »

I figured out the timer problem I reported below. The timer is being set and killed properly. My problem is really how to use the value returned when a modal form is closed. Unless the variable receiving the return code when the modal form closes is a global variable, how will other functions be aware of the value?

-----------------------------------------------------------------------------------------

I have a countdown timer on a form that works fine. When a certain button is clicked, I want to be able to pause the timer and have it resume after the user takes action. I tried killing the timer, asking for user input, and then recreating the timer to continue the countdown. The problem is that the timer continues to function even after it is killed. Is this a bug? If not, why is the timer not stopping after it is killed? The code I am using to create and kill the timer is:

SETTIMER HWND_FORM_TIMER1, 1, 1000, BYVAL %NULL
KILLTIMER HWND_FORM_TIMER1, 1
« Last Edit: December 28, 2008, 12:37:24 PM by RhodyRich »
Logged

TechSupport

  • Guest
Re: Modal Form Question
« Reply #1 on: December 28, 2008, 03:33:27 PM »

My problem is really how to use the value returned when a modal form is closed. Unless the variable receiving the return code when the modal form closes is a global variable, how will other functions be aware of the value?

You're right.... the variable would have to be global for other functions to be aware of the value. There really is no way around it. Global is the answer unless you want to get into more involved and complicated solutions.

Logged

RhodyRich

  • Guest
Re: Modal Form Question
« Reply #2 on: December 28, 2008, 05:47:06 PM »

Yes I solved the problem with a global variable but now I am still wondering about the timer issue. The code I was using was.

KILLTIMER HWND_FORM_TIMER1, 1
LL = MyModalForm_Show (HWND_MYMODALFORM, %TRUE)
SETTIMER HWND_FORM_TIMER1, 1, 1000, BYVAL %NULL

Why doesn't the timer stop while the modal form is waiting to be closed by the user?
Logged

BudDurland

  • Guest
Re: Modal Form Question
« Reply #3 on: December 28, 2008, 06:35:06 PM »

On one of my larger programs, I've seem an issue similar to what you describe.  I've gotten into the habit of adding SLEEP 250 after setting or killing a timer.
Logged

TechSupport

  • Guest
Re: Modal Form Question
« Reply #4 on: December 28, 2008, 10:28:47 PM »

I'm not 100% sure that I completely understand the problem but here is an idea. Create a global variable called, say, gKillingTimer and set it to TRUE just before you do the KILLTIMER. In the message handler for the TIMER you could check to see if gKillingTimer = %TRUE and then simply exit the handler.

Code: [Select]
gKillingTimer = %TRUE
KILLTIMER HWND_FORM_TIMER1, 1
LL = MyModalForm_Show (HWND_MYMODALFORM, %TRUE)
SETTIMER HWND_FORM_TIMER1, 1, 1000, BYVAL %NULL

'------------------------------------------------------------------------------------------------------------------------
Function FORM1_TIMER1_WM_TIMER ( _
                               hWndForm      As Dword, _  ' handle of Form
                               wTimerID      As Dword  _  ' the timer identifier
                               ) As Long
   
   If gKillingTimer = %TRUE Then Exit Function
   
End Function
« Last Edit: December 28, 2008, 10:32:33 PM by TechSupport »
Logged

TechSupport

  • Guest
Re: Modal Form Question
« Reply #5 on: December 28, 2008, 10:31:50 PM »

Uh, wait a second.... looks like your call to KILLTIMER is wrong.

The second parameter to the KillTimer should be the ID of the Timer control. You are using "1" as the value. You should use the IDC value which, incidently, starts at "1000", not "1".

KillTimer HWND_FORM_TIMER1, IDC_FORM_TIMER1

Likewise, when you create the timer use the IDC.

SetTimer HWND_FORM_TIMER1, IDC_FORM_TIMER1, 1000, ByVal %Null

Try that and see what happens.

:)

Logged