Solved

SetTimer

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

912 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

22 Experts available now in Live!

Get 1:1 Help Now