Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

Timer whitout m_hWnd

How can a make a timer in a non windows class. (no m_hWnd)
0
DAE
Asked:
DAE
  • 2
  • 2
1 Solution
 
AlexFMCommented:
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
 
DAEAuthor Commented:
Can you tell me a litle more about TimeSetEvent, Thanx
0
 
AlexFMCommented:
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
 
DAEAuthor Commented:
Thank you. AlexFM
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now