本文介绍了SetTimer的生成随机IDEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试使用Windows SetTimer函数,它产生,如果我已经指定了一个!计时器甚至 IDEvent
When I try to use the Windows SetTimer function, it generate a IDEvent for the timer even if I have specified one!
这
SetTimer(0,999,10000,@timerproc);
在
procedure timerproc(hwnd: HWND; uMsg: UINT; idEvent: UINT_PTR;dwTime: DWORD); stdcall;
begin
KillTimer(0, idEvent);
showmessage(inttostr(idevent));
end;
返回:
随机数!
是否有可能通过自己,而不是来管理的Windows选择对我来说我的计时器?
Is it possible to manage my timers by myself instead of Windows choosing for me?
非常感谢你!
推荐答案
如果你想处理在一个程序中处理多个定时器事件,然后通过特定的窗口处理它而不是特定常规:
If you want to handle multiple timer events in a single routine, then handle it by specific window rather then by specific routine:
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
FTimerWindow: HWND;
procedure TimerProc(var Msg: TMessage);
end;
...
procedure TForm1.FormCreate(Sender: TObject);
begin
FTimerWindow := Classes.AllocateHWnd(TimerProc);
SetTimer(FTimerWindow, 999, 10000, nil);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Classes.DeallocateHWnd(FTimerWindow);
end;
procedure TForm1.TimerProc(var Msg: TMessage);
begin
if Msg.Msg = WM_TIMER then
with TWMTimer(Msg) do
case TimerID of
999:
//
else:
//
end;
end;
这篇关于SetTimer的生成随机IDEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!