?
Solved

Timer whitout m_hWnd

Posted on 2003-03-22
4
Medium Priority
?
268 Views
Last Modified: 2013-11-20
How can a make a timer in a non windows class. (no m_hWnd)
0
Comment
Question by:DAE
[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
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 8189225
1) SetTimer function may be used with first hWnd parameter NULL. In this case you should provide TIMERPROC lpTimerFunc parameter and handle timer ticks in callback function.

2) You can use also multimedia timer (see timeSetEvent function). Multimedia timer has higher resolution and allows to pass user data to callback function.
0
 

Author Comment

by:DAE
ID: 8190026
Can you tell me a litle more about TimeSetEvent, Thanx
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 200 total points
ID: 8193412
Include Mmsystem.h and add Winmm.lib to the project library modules. Write timer callback function:

void CALLBACK TimeProc(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
{
    // ...
}

Start timer:

MMRESULT uTimerID = timeSetEvent(0, 10, TimeProc, 0, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);


You can pass to TimerCallback any data using dwUser parameter. To stop timer use timeKillEvent:

timeKillEvent(uTimerID);


Deatils about callback function;

void CALLBACK TimeProc(
  UINT uID,      
  UINT uMsg,    
  DWORD dwUser,  
  DWORD dw1,    
  DWORD dw2      
);
TimeProc is a placeholder for the application-defined function name.

Parameters
uID
Identifier of the timer event. This identifier was returned by the timeSetEvent function when the timer event was set up.
uMsg
Reserved; do not use.
dwUser
User instance data supplied to the dwUser parameter of timeSetEvent.
dw1
Reserved; do not use.
dw2
Reserved; do not use.



 
0
 

Author Comment

by:DAE
ID: 8193988
Thank you. AlexFM
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

770 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