Solved

SetTimer without windows

Posted on 1998-10-19
4
583 Views
Last Modified: 2012-06-22
I have an application which runs as service. The application does not has a window. How can I set a timer in the main program.

SetTimer needs a window. So I could create a class of CWnd which handles the timeout.

Is there an easier way to set a timer?
0
Comment
Question by:schmid
  • 2
4 Comments
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1175507
No , SetiTmer can works without Window. Now is part of
description SetTimer:

UINT SetTimer(hwnd, idTimer, uTimeout, tmprc)

HWND hwnd;      /* handle of window for timer messages      */
UINT idTimer;      /* timer identifier      */
UINT uTimeout;      /* time-out duration      */
TIMERPROC tmprc;      /* instance address of timer procedure      */
hwnd      Identifies the window to be associated with the timer.
 If the tmprc parameter is NULL, the window procedure associated with this window receives the WM_TIMER messages generated by the timer.
If this parameter(hwnd) is NULL, no window is associated with the timer.
Regards, Alex
0
 

Author Comment

by:schmid
ID: 1175508
I have still a problem with SetTimer. My code is like this:

static void CALLBACK EXPORT TimerProc(
   HWND hWnd,
   UINT nMsg,
   UINT nIDEvent,
   DWORD dwTime)
{
  some code
}

SetTimer(NULL, 1, 1000, TimerProc);

The function call SetTimer returns with success. But the callback function TimerProc is not called. What is wrong in my code?
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1175509
>> The function call SetTimer returns with success. But the callback function TimerProc is not called. What is wrong in my code?

You need a message loop .  Whether you have a window or not, timer messages are only sent via this.
0
 

Author Comment

by:schmid
ID: 1175510
Thanks, Answers 2000
0

Featured Post

Independent Software Vendors: 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

685 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