Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetTimer and KillTimer doesn't work in console application

178 views
Skip to first unread message

Dave Nottage (TeamB)

unread,
May 23, 2003, 1:40:19 AM5/23/03
to
setankabir wrote:
> Why SetTimer and KillTimer function doesn't work in console
> application?

Are you passing a valid window handle or timer ID? Some code would help.

--
Dave Nottage (TeamB)


setankabir

unread,
May 23, 2003, 2:03:16 AM5/23/03
to

Brian Cook

unread,
May 23, 2003, 2:01:23 AM5/23/03
to
> Why SetTimer and KillTimer function doesn't work in console application?

I do believe that it is necessary to process Windows messages in order for
SetTimer to work. Does your application make a call to GetMessage,
PeekMessage, or DispatchMessage?

Of course, I could be wrong.

- Brian

Dave Nottage (TeamB)

unread,
May 23, 2003, 2:59:23 AM5/23/03
to
Brian Cook wrote:
>> Why SetTimer and KillTimer function doesn't work in console
>> application?
>
> I do believe that it is necessary to process Windows messages in
> order for SetTimer to work.

It's not necessary if using a TimerProc callback function.

--
Dave Nottage (TeamB)


Brian Cook

unread,
May 23, 2003, 3:21:05 AM5/23/03
to
> >> Why SetTimer and KillTimer function doesn't work in console
> >> application?
> >
> > I do believe that it is necessary to process Windows messages in
> > order for SetTimer to work.
>
> It's not necessary if using a TimerProc callback function.

Give this a try...

program Project2;
{$APPTYPE CONSOLE}
uses
Windows;
var
TimerId: UINT;
procedure TimerProc( Handle: HWND; uMsg: UINT; idEvent: UINT; dwTime:
DWORD ); stdcall;
begin
KillTimer( 0, TimerId );
MessageBox( 0, 'Yo!', 'Yo!', MB_OK );
end;
procedure Pump;
var
M: TMsg;
begin
while GetMessage( M, 0, 0, 0 ) do
DispatchMessage( M );
end;
begin
TimerId := SetTimer( 0, 0, 100, @TimerProc );
Readln;
// Pump;
end.


...and then this...


program Project2;
{$APPTYPE CONSOLE}
uses
Windows;
var
TimerId: UINT;
procedure TimerProc( Handle: HWND; uMsg: UINT; idEvent: UINT; dwTime:
DWORD ); stdcall;
begin
KillTimer( 0, TimerId );
MessageBox( 0, 'Yo!', 'Yo!', MB_OK );
end;
procedure Pump;
var
M: TMsg;
begin
while GetMessage( M, 0, 0, 0 ) do
DispatchMessage( M );
end;
begin
TimerId := SetTimer( 0, 0, 100, @TimerProc );
// Readln;
Pump;
end.


Have a good weekend, Brian

Dave Nottage (TeamB)

unread,
May 23, 2003, 6:44:56 AM5/23/03
to
Brian Cook wrote:
> Give this a try...

That'll teach me to read all of the help on SetTimer.

program Project1;

{$APPTYPE CONSOLE}

uses
Windows;

var
TimerId: UINT;

procedure TimerProc(Handle: HWND; uMsg: UINT; idEvent: UINT; dwTime:DWORD);
stdcall;
begin
if Integer(KillTimer(0, idEvent)) <> 0 then
MessageBox(0, 'Yo!', 'Yo!', MB_OK);
TimerId := 0;
end;

procedure Pump;
var
M: TMsg;
begin

while (TimerID <> 0) and GetMessage(M, 0, 0, 0) do
DispatchMessage(M);
end;

begin
TimerId := SetTimer(0, 1, 100, @TimerProc);
Pump;
Readln;
end.

--
Dave Nottage (TeamB)


Peter Below (TeamB)

unread,
May 23, 2003, 7:38:12 AM5/23/03
to
In article <3ecdc6b3$1...@newsgroups.borland.com>, Dave Nottage (TeamB)
wrote:

> > I do believe that it is necessary to process Windows messages in
> > order for SetTimer to work.
>
> It's not necessary if using a TimerProc callback function.

Wrong. The callback is fired my the message loop code instead of putting
a WM_TIMER message into the queue. In an application that has no message
loop one has to use a secondary thread as timer.

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


setankabir

unread,
May 24, 2003, 2:57:44 AM5/24/03
to
I'm listening


0 new messages