可以有Form的,另建一个窗口,从服务主程序中调用<br>比如我的例子:<br>unit MyPowerKey;<br>interface<br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;<br><br>type<br> TPower_Key = class(TService)<br> procedure ServiceCreate(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> function GetServiceController: TServiceController; override;<br> procedure WMPowerBroadCast(var msg : TMessage);message WM_POWERBROADCAST;//键盘Power键或系统关机的广播消息<br> { Public declarations }<br> end;<br><br>var<br> Power_Key: TPower_Key;<br><br>implementation<br>uses MsgBox;<br>{$R *.DFM}<br><br>procedure TPower_Key.WMPowerBroadCast(var msg: TMessage);<br>var Form_MsgBox : TForm_MsgBox;<br>begin<br> //SetForeGroundWindow(Application.MainForm.Handle);//在应用程序里指定主窗口前置,可获取按键消息,服务没有窗口,所以就屏蔽这行了<br> Form_MsgBox := TForm_MsgBox.Create(nil);//自定义提示窗口<br> try<br> Form_MsgBox.suiForm1.Caption := '提醒框';<br> Form_MsgBox.HintsLabel.Caption := '确认是否关闭系统?';<br> if Form_MsgBox.ShowModal <> mrOK then<br> msg.Result := BROADCAST_QUERY_DENY;//修改消息值,使不关机<br> finally<br> FreeAndNil(Form_MsgBox);<br> end;<br>end;<br><br>procedure ServiceController(CtrlCode: DWord); stdcall;<br>begin<br> Power_Key.Controller(CtrlCode);<br>end;<br><br>function TPower_Key.GetServiceController: TServiceController;<br>begin<br> Result := ServiceController;<br>end;<br><br>procedure TPower_Key.ServiceCreate(Sender: TObject);<br>begin<br> Self.Interactive := true;<br>end;<br>end.