Solved

SetTimer without windows

Posted on 1998-10-19
4
550 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now