正常退出应用程序 [英] To exit the application gracefully
问题描述
大家好..
在某些情况下感到震惊,让我解释一下..我的代码段代码如下所示.
//CSampleDlg.cpp
Hi All..
Am struck up in certain situation, Let me explain this.. My snippet code looks like this.
//CSampleDlg.cpp
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
}
}
我必须连续运行MyTimerProc函数.某些小时后,我必须退出该函数.
I have to run MyTimerProc function continuously.After certain hours i have to quit that function.
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);
}
当我单击取消按钮时,无论如何MyTimerProc函数将退出.但我的担心是..当我单击取消"按钮&时,控件位于Open_Position()或Close_Position()之类的中间操作中.在这种情况下,Open_Position()或Close_Operation()将会失败&应用程序不会正常退出.
当用户点击取消"按钮&如果MyTimerProc函数正在执行Open_Position()/Close_position(),那么我可以得到任何通知还是像警报一样.
请给我建议..
谢谢大家.
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.
推荐答案
如果您的计时器工作仅与对话框有关-
只需将NULL
作为第三个参数传递给SetTimer(..)
然后让对话框在WM_TIMER
上为您的事件ID做出反应:)
另请注意
取消对话
不是离开它的唯一方法
(您可以在WM_DESTROY
上的反应中杀死(创建的)计时器):)
If your timer''s job related to the dialog only -
just passNULL
as third parameter to theSetTimer(..)
and then let the dialog react onWM_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 onWM_DESTROY
) :)
这篇关于正常退出应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!