代码:Unit1单元<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> procedure Button1Click(Sender: TObject);<br> <br> private<br> { Private declarations<br> }<br> procedure WMClose(var Msg: TMessage); Message WM_CLOSE;<br> procedure WMQUERYENDSESSION(var Msg: TMessage); Message WM_QUERYENDSESSION;<br> public<br> { Public declarations }<br> <br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>uses Unit2;<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> Form2.Show;<br>end;<br><br>procedure TForm1.WMClose(var Msg: Tmessage);<br>begin<br> if msg.Msg=WM_CLOSE then<br> begin<br> showmessage('WM_CLOSE');<br> close;<br> end;<br>end;<br><br>procedure TForm1.WMQUERYENDSESSION(var Msg: Tmessage);<br>begin<br> if msg.Msg=WM_QUERYENDSESSION then<br> begin<br> showmessage('WM_QUERYENDSESSION');<br> close;<br> end;<br>end;<br><br>end.<br>//----------------------------------------------<br>Unit2单元<br>unit Unit2;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs;<br><br>type<br> TForm2 = class(TForm)<br> procedure FormShow(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form2: TForm2;<br> WindowList: Pointer;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm2.FormShow(Sender: TObject);<br>begin<br> WindowList := DisableTaskWindows(0);<br>end;<br><br>procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> EnableTaskWindows(WindowList);<br>end;<br><br>end.