Solved

SetTimer without windows

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

863 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

19 Experts available now in Live!

Get 1:1 Help Now