Solved

SetTimer

Posted on 1998-12-08
1
710 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 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.

739 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