Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

jolkkone

Help needed with SetTimer()

This topic is 6612 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Please help me. I can''t get SetTimer() to work right. Initalization succeeds, but timer never lauches either the TimeProc or the WM_TIMER-event. My call is something like: SetTimer(hWnd,TIMERX,1000,(TIMERPROC)timeproc); If I got that right, SetTimer() should only throw a WM_TIMER event, with the last parameter as NULL and that would be just what I need. The Multimedia timer works fine, but it crashes if run under the Builder and it makes debugging harder. And besides, the basic Timer is good enough for my purposes. Have anyone come accross the same problem, or have an idea what on earth can be wrong in such a simple thing. JO

Share this post


Link to post
Share on other sites
Advertisement
SetTimer EITHER sends a WM_TIMER message to your window, OR calls the proc you supply.
so if you want to catch a message instead of supplying a function, just put 0 instead of timeproc.

SetTimer(hWnd,TIMER_ID,1000,0);

also make sure that TIMER_ID is a value between 0 and 32

Share this post


Link to post
Share on other sites
Yep, that''s what the help said, but doesn''t work. Message WM_TIMER never appears.
I''m beginning to suspect, that there''s something weird in my windows-headers...

Share this post


Link to post
Share on other sites
TimeProc needs to be a static function. Something that''s never mentioned in the docs, so I missed it the first time too.

Share this post


Link to post
Share on other sites
At last I found a reason!! Don''t ask why, but if you catch a WM_PAINT in your message-handler, you never get WM_TIMER!
A simple example program worked, so I added my code there line after line until WM_TIMER messages stopped. Boy, that took time.. Can anyone explain why WM_PAINT prevents WM_TIMER messages to arrive? Any other messages seemed not to have the same problem. Amazing isn''t it?

JO

Share this post


Link to post
Share on other sites
If you always have some form of WM_PAINT message pending (like WM_TIMER, WM_PAINT doesn''t really get queued), then WM_TIMER messages will never be generated.

Take a look at the article "GetMessage and PeekMessage Internals"

http://msdn.microsoft.com/library/techart/msdn_getpeek.htm

Tim

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!