Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetTimer() for application without window 2

Status
Not open for further replies.

mingis

Programmer
Jan 23, 2002
475
LT
I would like to start Windows timer using
SetTimer(HWND hWnd, UINT nIDEvent, ...);
My application has no window, it simply starts a child thread and waits for messages from that thread. My wish is to have a some timeout timer to proceed the job for the case, when something wrong is happened with that child thread. The problem is that SetTimer() works problemmatically with argument hWnd==NULL. Parameter of WM_TIMER message in such case does contain value different from the timer identifier nIDEvent, what should be in the normal case, so I cannot distinguish message of what timer is arrived. Another problem - such a timer cannot be killed. Once started, timeout messages are comming all the time. Is there may be some other way to deal with timers without application window? Operating system I'm currently using is Windows98.
 
specify the timeout value in milliseconds in the third parameter.

Ion Filipski
1c.bmp
 
Sure, I do it. The timer works correctly, it isn't the problem. Wrong are WM_TIMER messages - they do not contain a timer identifier I have set in SetTimer(). Also KillTimer() does not work with that identifier.
 
If program has no visual interface there is no reason to create a window.

mingis, use a static counter of calling the timer function. On first call of that function only increase the calling counter return from function with doing nothing. On next call verify the counter and if the value is for example 1, then do everything else.

Ion Filipski
1c.bmp
 
Static counter - OK. But what in the case, if I need two timers simultaneously - how can I distinguish between them?
 
In the WndProc or in the TimerProc, the third parameter is the TimerID, it is the ID of timer what was returned by function CreateTimer.

Ion Filipski
1c.bmp
 
> In the WndProc or in the TimerProc, the third parameter is the TimerID, it is the ID of timer what was returned by function CreateTimer.

No, that parameter contains some value, constant during certain instance of application, but different from timer ID value, I have set in CreateTimer() function.
 
You can not set the ID of timer. It is generated dinamically, and is the hTimer returned by function SetTimer.

Ion Filipski
1c.bmp
 
I'm using settimer but its nowhere near as fast as i need it. Anyoneknow of a way to have a timer that can tick as fast as 1000+ times a second and at the same time in between those ticks have other processes running instead of having to wait in the maindialogproc
 
Can you achieve speed of 1000 times per second? What is the level of computer resource consumption at that speed? Is the computer still usable for other work? In 1 GHz processor for one timer message it will give 1,000,000 ticks = 10,000 processor instructions = 1000 C-like statements - not so many for normal system work. I think you could switch to single user mode, to MS-DOS and program then timer frequency directly as you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top