Solved

SetTimer

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

820 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