关机消息:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;<br><br>type<br> TForm1 = class(TForm)<br> private<br> { Private declarations }<br><br> public<br> { Public declarations }<br> procedure MyShutDown(var Message:TMessage );Message WM_USERCHANGED; //更改当前用户<br> procedure MyEndsession(var Message:TMessage );Message WM_ENDSESSION;//注消当前用户<br> procedure MyQuseryEnd(var Message:TMessage );Message WM_QUERYENDSESSION;//关机或重新启动<br> procedure ExitApp();//自定义退出函数<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br><br>procedure TForm1.MyEndsession(var Message:TMessage );<br>begin<br> ExitApp();<br> inherited ; //继承Windows原消息处理机制,不能省,否则此消息会被你的程序堵塞,其他程序无法响应<br>end;<br>procedure TForm1.MyQuseryEnd(var Message:TMessage );<br>begin<br> ExitApp();<br> inherited ;<br>end;<br>procedure TForm1.MyShutDown(var Message:TMessage );<br>begin<br> ExitApp();<br> inherited ;<br>end;<br><br>procedure TForm1.ExitApp();<br>begin<br> Application.messagebox('windows close ','information',mb_ok);<br> if Not Form1.Visible Then<br> Begin<br> Form1.show;<br> BringWindowToTop(Application.Handle);<br> Application.Restore;<br> SetForegroundWindow(Application.Handle);<br> End;<br> Form1.Close;<br>end;<br>end.<br>