Solved

SetTimer

Posted on 1998-12-08
1
706 Views
Last Modified: 2006-11-17
Hi... I have a dialog based MFC app. In OnInitDialog, I start a timer with 1000msec delay. I use the standard SetTimer. Whenever the time passes, I call WM_TIMER and run an algorithm. My question is this: the algorithm I run is very important and needs to be precise. But WM_TIMER is a low priority message. How do I improve the accuracy, or how do I make the message more high priority? I want to try avoid multimedia timers because I have tried them and got lost. Standard SetTimer is nice and simple.
0
Comment
Question by:rose3377
1 Comment
 
LVL 6

Accepted Solution

by:
snoegler earned 50 total points
ID: 1179530
Please try this code (multimedia timers):

// Global variable:
UINT uTimerID;

void CALLBACK MyTimerProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
  if(uID!=uTimerID) return;
   // Do your work here
}

.
// somewhere in your app
  DWORD dwUser=0;// argument to MyTimerProc
  uTimerID=timeSetEvent(1000,0,(LPTIMECALLBACKPROC)MyTimerProc,
                                             dwUser, TIME_PERIODIC);

// Cleanup:
  timeKillEvent(uTimerID);

This code sets up a multimedia timer with the maximum possible resolution
(uResolution=0), and passed one user defined argument to it (dwUser). This could be a
pointer to the class you originally had the 'OnTimer()' routine in. Passing it this way allows
to access the class members within 'MyTimerProc'.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now