Click here to Skip to main content
15,887,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All..

Am struck up in certain situation, Let me explain this.. My snippet code looks like this.

//CSampleDlg.cpp
C++
void CALLBACK EXPORT MyTimerProc(HWND hWnd,UINT nMsg,UINT nIDEvent,DWORD dwTime)
{
   // Task 1: Am reading the values SellA,BuyB & SellB,BuyA.
   
   //Task 2: 
   if( SellA >= BuyB)
   {
      //Do Other Stuff: Open_Position() operation
   }

   if( SellB >= BuyA )
   {
      //Do other stuff: Close_Position() Operation
   }

}


I have to run MyTimerProc function continuously.After certain hours i have to quit that function.

C++
UINT m_timer;
void CSampleDlg::OnOK()
{
//For Every 2seconds, MyTimerProc will run continously.
 m_timer=SetTimer(1, 2000, (TIMERPROC)MyTimerProc);
}

void CSampleDlg::OnCancel()
{
//To Terminate the MyTimerProc function
KillTimer(m_timer);
}


When i click on cancel button, Anyhow MyTimerProc function will quit. But My fear is.. When i click on cancel button & control is in the middle operation like Open_Position() OR Close_Position(). In such case, Open_Position() OR Close_Operation() will fail & application will not exit gracefully.

Is it possible, when user clicks on cancel button & if MyTimerProc function is doing Open_Position()/Close_position(), then can i get the any notifiction or just like alarm..
Please suggest me on this..

Thank you all.
Posted

1 solution

If your timer's job related to the dialog only -
just pass NULL as third parameter to the SetTimer(..)
and then let the dialog react on WM_TIMER for your event ID :)

Please note also
that the cancelling of a dialog
is not the single way to leave it
(you could kill the (created) timer in the reaction on WM_DESTROY) :)
 
Share this answer
 
Comments
Guru_C++ 31-Aug-12 5:09am    
sorry.. I dint understood..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900