Windows SetTimer生成一个随机IDEvent
当我尝试使用Windows SetTimer函数时,它会为计时器生成一个IDEvent,即使我已经指定了一个强> 这: 在: 返回: 随机数强> 可以自己管理计时器而不是为我选择Windows吗Windows SetTimer生成一个随机IDEvent,windows,delphi,api,timer,Windows,Delphi,Api,Timer,当我尝试使用Windows SetTimer函数时,它会为计时器生成一个IDEvent,即使我已经指定了一个 这: 在: 返回: 随机数 可以自己管理计时器而不是为我选择Windows吗 多谢各位 SetTimer的工作方式将有所不同,具体取决于您是否向其传递窗口句柄 Timer_Indentifier := SetTimer(0, MyIdentifier, Time, @myproc); 在上面的实例中,Timer_Identifier不等于MyIdentifier Timer_Inden
多谢各位 SetTimer的工作方式将有所不同,具体取决于您是否向其传递窗口句柄
Timer_Indentifier := SetTimer(0, MyIdentifier, Time, @myproc);
在上面的实例中,Timer_Identifier不等于MyIdentifier
Timer_Indentifier := SetTimer(handle, MyIdentifier, Time, @myproc);
在第二个示例中,Timer\u Identifier=MyIdentifier
Timer_Indentifier := SetTimer(handle, MyIdentifier, Time, @myproc);
这是因为在第二个示例中,您的windows循环将需要使用“MyIdentifier”来确定哪个计时器正在向其发送“WM_timer”消息
使用没有窗口句柄的特定计时器功能是不同的。简而言之,在您的场景中,使用Windows提供的值
多媒体定时器解决了我的问题 我可以使用
dwUser
:)将我想要的任何内容传递给他们
从MSDN:dwUser->用户提供的回调数据
- 他们有一个
选项,这正是我使用计时器的目的李>TIME\u ONESHOT
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;
因为每个IDEvent在
TimerProc
回调中都有一个唯一的函数。我使用这个变量来传递指令。例如,在我的TimerRoc中,我有:case IdEvent of 999:然后在正确的计时器事件中执行相应的操作!你分类了,很好。FWIW,您从IdeEvent获得的随机值等于从SetTimer返回的值。我用另一种方法解决了我的问题,但您的答案修复了它!所以这将是这个问题的公认答案。谢谢!:)
MMRESULT timeSetEvent(
UINT uDelay,
UINT uResolution,
LPTIMECALLBACK lpTimeProc,
DWORD_PTR dwUser,
UINT fuEvent
);
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;