WM_TIMER消息来自哪里? [英] where does the WM_TIMER message come from?
本文介绍了WM_TIMER消息来自哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
IMPLEMENT_DYNCREATE(CWorkThread, CWinThread)
CWorkThread::CWorkThread()
{
m_uTimer = -1;
}
CWorkThread::~CWorkThread()
{
}
BOOL CWorkThread::InitInstance()
{
// TODO: 在此执行任意逐线程初始化
return TRUE;
}
int CWorkThread::ExitInstance()
{
// TODO: 在此执行任意逐线程清理
return CWinThread::ExitInstance();
}
void CWorkThread::OnTimer(WPARAM wp, LPARAM lp)
{
KillTimer(NULL, m_uTimer);
m_uTimer = UINT_PTR(-1);
CTestDlg dlg;
dlg.DoModal();
m_uTimer = SetTimer(NULL, 1, 4000, NULL);
}
void CWorkThread::OnStartProcess(WPARAM wp, LPARAM lp)
{
if (m_uTimer != UINT_PTR(-1))
{
KillTimer(NULL, m_uTimer);
m_uTimer = UINT_PTR(-1);
}
m_uTimer = SetTimer(NULL, 1, 4000, NULL);
int i=0;
}
BEGIN_MESSAGE_MAP(CWorkThread, CWinThread)
ON_THREAD_MESSAGE(WM_TIMER, OnTimer)
ON_THREAD_MESSAGE(WM_STARTPROCESS, OnStartProcess)
END_MESSAGE_MAP()
这是我的代码的一部分.计时器在Windows XP上可以正常运行,但是在7窗口上却无法正常运行.启动计时器后,将弹出一个对话框,除了外观外我什么也没做,并且对话框不断弹出.我的问题是,对话框第一次弹出时,计时器已停止,以下wm_timer消息从哪里来?
谢谢.
This is part of my code. The timer runs OK on windows xp,but it runs abnormally on window 7. When timer has been started, a dialog box pop up, and I don''t do anything except look, and the dialog box pop up continually. My question is when the dialog box first pop up,the timer has been stopped, where do the following wm_timer message come from?
thank you.
推荐答案
从代码中可以明显看出,在调用dlg.DoModal
之后,您在计时器回调中一次又一次地设置了计时器.我不知道它如何在任何操作系统上工作.在计时器消息上显示模式对话框的整个想法看起来很奇怪,但这不是问题的根源.
—SA
It is apparent from your code that you set timer again and again inside timer callback after the call todlg.DoModal
. I have no idea how it could work in any OS. The whole idea to show a modal dialog on timer message looks weird, but this is not a source of your problem.
—SA
这是一个独立的线程,您确定在处理最后一条消息时另一个线程没有在调用WM_STARTPROCESS吗?您也不会检查KillTimer()
是否成功,也不会检查WM_TIMER消息随附的计时器标识符.
http://msdn.microsoft.com/en-us/library/ms644902%28v = vs.85%29.aspx [ ^ ]
This is an independent thread, are you sure another thread isn''t calling WM_STARTPROCESS while you''re processing the last message? You''re also not checking ifKillTimer()
succeeded and not checking the timer identifier that comes in with the WM_TIMER message.
http://msdn.microsoft.com/en-us/library/ms644902%28v=vs.85%29.aspx[^]
这篇关于WM_TIMER消息来自哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文