我想在dll中实现实现定时器(settimer)但不能实现,偶在有form的程序里可以实现,请问各位大虾怎么弄??或者
在dll 实现定时器功能?最好能给出code,谢谢!(在网上看了三种方法但都没实现,很是郁闷)
在dll 实现定时器功能?最好能给出code,谢谢!(在网上看了三种方法但都没实现,很是郁闷)
解决方案 »
- TPageControl.tabsheet1 动态创建控件实如何现单击事件???
- error in module:call to application.create form is missing or incorrect
- 多线程的问题?初手请教
- 有关dll的一个问题?
- sql引用变量
- 请看一段代码。帮帮忙!急,在线!!!!
- 怎样用宽带!
- 帮帮我吧~~~~~~~~My God!!!!!!我不得已而为之啊~~~急急急急急急急!!!
- 如果在一个表中使用了触发器,如何在Delphi中判断这个触发器是否进行了回滚操作?
- 哪位大神会c#,帮忙翻译成delphi,谢谢!
- dbgrideh中粘贴数据
- 如何让自己的界面显示在别人的窗口上。
TMyThread = class(TThread)
private
FTimer:TTimer;
procedure TimerProc(Sender: TObject);
protected
procedure Execute;override;
public
constructor Create;override;
procedure KillIt;//结束
end;
implementation
procedure TMyThread.TimerProc(Sender: TObject);
begin
...
end;
procedure TMyThread.KillIt;
begin
PostMessage(Handle,WM_QUIT,0,0);
end;
procedure TMyThread.Execute;
begin
FTimer:=TTimer.Create(nil);
try
try
FTimer.Enabled:=false;//需要用的时候Enabled设置为True即可。
FTimer.OnTimer:=TimerProc;
while GetMessage(MsgRec, 0, 0, 0) do begin
TranslateMessage(MsgRec);
DispatchMessage(MsgRec)
end;
Terminate;
finally
FSocket.Free;
end;
finally
FTimer.Free;
end;
end;
要结束的话,往线程的Handle发送一个WM_QUIT消息,本例当中调用KillItvar
T: TMyThread;
begin
...
T.KillIt;
end;
procedure TimerProc(hwnd:HWND;uMsg:UINT; idEvent :UINT_PTR;dwTime:DWORD);stdcall;
begin
//add your code.
end;
//....begin
settimer(0,0,1000,@TimerProc);
end.
type
TTimeProcCall = procedure(hand: THandle; Msg, Identer, dwTime: DWord) of object; stdcall; //定时器函数指针
function TMyTime.CreateTime(Time: Dword; Porc: TTimeProcCall): boolean; //创建
begin
Result := Windows.SetTimer(FHwnd,Dword(Self), Time, @Porc) <> 0;
end;
function TMyTime.FreeTime: boolean;//销毁
begin
Result := KillTimer(FHwnd, Dword(Self));
end;
procedure TMyTime.TimeProc(hand: THandle; Msg, Identer, dwTime: DWord); stdcall; //回调过程
begin
....//TimeProc
end;
UINT_PTR SetTimer( HWND hWnd,
UINT_PTR nIDEvent,
UINT uElapse,
TIMERPROC lpTimerFunc
);
ParametershWnd
[in] Handle to the window to be associated with the timer. This window must be owned by the calling thread. If this parameter is NULL, no window is associated with the timer and the nIDEvent parameter is ignored.hwnd参数可以传入NULL,所以,不一定需要window