O
only you
Unregistered / Unconfirmed
GUEST, unregistred user!
定义一个消息,截获WM_QUERYENDSESSION,然后进行处理。看一下代码:<br>////////////////////////////////////<br>//一个在系统关机时检测光驱中是否有光盘<br>//的程序。如有则弹出光驱。5秒后系统关闭<br>//<br>////////////////////////////////////<br>unit Main;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,mmSystem,<br> ExtCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Timer1: TTimer;<br> procedure WMQueryEndSession(var Message: TWMQueryEndSession); message WM_QUERYENDSESSION;<br> procedure Timer1Timer(Sender: TObject);<br> procedure CMEraseBkgnd(var Message:TWMEraseBkgnd);Message WM_ERASEBKGND;<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br>function DiskInDrive(const Drive: char): Boolean;stdcall;external 'DevWolf.DLL'<br>function DiskIsCDROMchar;stdcall external 'DevWolf.Dll'<br><br>procedure TForm1.WMQueryEndSession(var Message: TWMQueryEndSession);<br>var<br> WaitPanel,bkPanel: TPanel;<br> i:integer;<br> Drivechar;<br>begin<br> inherited;<br> i:=5;<br> Drive:=DiskIsCDROM;<br> copy(drive,0,1);<br> if Drive<>'0' then<br> begin<br> if DiskInDrive(Drive^) then<br> begin<br> WaitPanel:=TPanel.create(Form1);<br> bkPanel:=Tpanel.Create(form1);<br> with BKPanel do<br> begin<br> Parent:=Form1;<br> Left:=5;<br> Top:=5;<br> Width:=200;<br> Height:=50;<br> color:=clBlack;<br> ctl3d:=False;<br> visible:=true;<br> show;<br> end;<br> with WaitPanel do<br> begin<br> Parent:=Form1;<br> Left:=0;<br> Top:=0;<br> Width:=200;<br> Height:=50;<br> Font.Size:=11;<br> Font.Name:='宋体';<br> visible:=true;<br> form1.Show;<br> show;<br> mciSendString('Set cdaudio door open wait', nil, 0, handle);<br> while i>=0 do<br> begin<br> WaitPanel.Caption:='光盘关闭的时间还余'+Inttostr(i)+'秒';<br> i:=i-1;<br> sleep(1000);<br> Form1.Update;<br> end;<br> mciSendString('Set cdaudio door closed wait', nil, 0, handle);<br> end;<br> end;<br> end<br> else<br> begin<br> Showmessage('你的电脑没有安装光驱');<br> end;<br>end;<br><br>procedure TForm1.CMEraseBkgnd(var Message: TWMEraseBkgnd);<br>begin<br>brush.style:=bsClear;<br>Inherited;<br>end;<br><br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br>Form1.Hide;<br>Timer1.Enabled:=False;<br>end;<br>end.