Solved

SetTimer without windows

Posted on 1998-10-19
4
575 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 Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

839 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