implementation
uses MMSystem;
const
MW_TIMER_TEST = WM_USER + 100;
procedure TimerCallBackProc(uTimerID, uMsg: Integer; dwUser, dwParam1, dwParam2: LongWord);
stdcall;
begin
PostThreadMessage(HWND(dwUser), MW_TIMER_TEST, 0, 0);
end;
procedure TFrmTimerTest.Start;
const
MaxCount = 10000;
var
TimerMsg: TMsg;
TimerProc: TTimerProc;
TimerInterval, TimerID, TimerCount, Counter: Integer;
CloseRequested: boolean;
TimerReturnMsg: Longbool;
begin
Counter := 0;
TimerInterval := 10;
TimerCount := 0;
TimerProc := TimerCallBackProc;
TimerID := timeSetEvent(TimerInterval, TimerInterval, @TimerProc,
GetCurrentThreadId, TIME_PERIODIC);
if TimerID = 0
then begin
timeEndPeriod(TimerInterval);
Exit;
end;
Memo.Lines.Clear;
edStartTickCount.Tag := GetTickCount;
edStartTickCount.Text := IntToStr(edStartTickCount.Tag);
repeat
TimerReturnMsg := GetMessage(TimerMsg, 0, 0, 0);
Inc(Counter);
if Counter > MaxCount
then break;
if TimerMsg.
Message = MW_TIMER_TEST
then
begin
Inc(TimerCount);
// Anzeige, damit der VCL-Thread auch ein bisserl was zu tun hat
Memo.Lines.Add('
Count:'+IntToSTr(TimerCount));
end;
TranslateMessage(TimerMsg);
DispatchMessage(TimerMsg);
until (integer(TimerReturnMsg) <= 0);
edStopTickCount.Tag := GetTickCount;
edStopTickCount.Text := IntToStr(edStopTickCount.Tag);
edDiffTickCount.Tag := edStopTickCount.Tag - edStartTickCount.Tag;
edDiffTickCount.Text := IntToStr(edDiffTickCount.Tag);
timeKillEvent(TimerID);
timeEndPeriod(TimerInterval);
end;