Solved

SetTimer

Posted on 1998-12-08
1
708 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

813 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

12 Experts available now in Live!

Get 1:1 Help Now