Solved

SetTimer without windows

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What does std::atomic give me? 7 124
object modeling - load and save functions 5 61
How to gracefully close the c++ 11 thread? 3 95
Unable to start eclipse ? 17 141
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 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…

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