Timer multimedia avec mmsystem
Bonjour , je suis actuellement en train de tester les timers dits multimedia avec l'unité mmsystem.Pour une raison étrange , le code ci-dessous ne marche que quand un showmessage est appellé , juste avant l'assignation du callback.Je cherche une explication rationelle à celà.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
implementation
{$R *.dfm}
procedure FNTimeCallback(uTimerID,uMsg:UINT;dwUser,dw1,dw2:DWORD);stdcall;
begin
Form1.OnTimer;
end;
function TForm1.InitTimer:UINT;
begin
result := timeSetEvent(1000,1,FNTimeCallback,DWORD(self),Time_periodic);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if TimerID<>-1 then
begin
timeEndPeriod(1);
timeKillEvent(TimerID) ;
end;
timeBeginPeriod(0);
// ShowMessage(inttostr(self.Handle)); //dummy message: marche/marche pas !!
TimerID := InitTimer; // marche si showmessage juste avant
end;
procedure TForm1.OnTimer;
begin
ShowMessage('Multimedia timer event');
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if TimerID<>-1 then
begin
timeEndPeriod(1);
timeKillEvent(TimerID) ;
end;
end;
end. |
Ca semble être un problème de handle ou autre...si quelqu'un pourrait trouver la solution à cet obscure problème ca serait...cool.