Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetTimer not calling OnTimer?

528 views
Skip to first unread message

SteveS

unread,
Sep 9, 2009, 10:59:28 AM9/9/09
to
studio 2005 vc8

my code : -------------------------------------------


UINT nHandle = StartTimer(5000);

UINT CMainFrame::StartTimer(int nInterval)
{
UINT nTimer = SetTimer(1, nInterval, NULL);
return nTimer;
}

void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
DoStuff();

//default handling
CFrameWnd::OnTimer(nIDEvent);
}

//------------------------------------------------

OnTimer in never called!

Am i missing something?

Thanks


Guido Franzke

unread,
Sep 9, 2009, 11:34:19 AM9/9/09
to
Your code is ok.
Do you have OnTimer in your message map?

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_TIMER()
...

HTH Guido

"SteveS" <sser...@wagstaff.com> schrieb im Newsbeitrag
news:OAkeh4VM...@TK2MSFTNGP06.phx.gbl...

Scott McPhillips [MVP]

unread,
Sep 9, 2009, 12:13:57 PM9/9/09
to
You didn't make it clear where you are calling StartTimer. If you call it
before the CMainFrame window has been created then it cannot work. Calling
SetTimer from CMainFrame::OnCreate would work.

"SteveS" <sser...@wagstaff.com> wrote in message
news:OAkeh4VM...@TK2MSFTNGP06.phx.gbl...

--
Scott McPhillips [VC++ MVP]

SteveS

unread,
Sep 9, 2009, 12:43:49 PM9/9/09
to
Yes, I have the ON_WM_TIMER() mapped and I'm calling it well after creation.

I do have timers in other apps that work just fine, I can't seem to nail
this one down.


"SteveS" <sser...@wagstaff.com> wrote in message
news:OAkeh4VM...@TK2MSFTNGP06.phx.gbl...

SteveS

unread,
Sep 9, 2009, 12:58:02 PM9/9/09
to
I got it, I got rid of a mapped call to a slider control.
Somehow it was interfering with the works. Don't ask me why.

Thanks for the help gang.

Steve

"SteveS" <sser...@wagstaff.com> wrote in message
news:OAkeh4VM...@TK2MSFTNGP06.phx.gbl...

Joseph M. Newcomer

unread,
Sep 9, 2009, 2:32:40 PM9/9/09
to
More context is required here. For example, it is a common error to think that OnTimer
will be called every nInterval, but nobody mentions "I'm off doing a long computation".
Since WM_TIMER messages are dispatched ONLY when the message pump is running, and a long
computation blocks the message pump, this would not work under those conditions.

You have given far too much out of context here; you corrected at least one point and said
that you know the window actually exists when SetTimer is called, and you have an
ON_WM_TIMER in your Message Map. So you need to clarify the conditions. Note that if you
want 1-second notifications while a long computation is running, doing the long
computation in the main thread is a mistake. You would want to do the long computation in
a secondary thread.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages