Modal Form Question

Started by RhodyRich, December 28, 2008, 12:50:07 PM

Previous topic - Next topic

RhodyRich

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

TechSupport

Quote from: RhodyRich on December 28, 2008, 12:50:07 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.


RhodyRich

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?

BudDurland

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.

TechSupport

#4
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.


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


TechSupport

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.

:)