一、把当前进程变为一个系统服务: <br>目的是在任务列表中把程序隐藏起来。调用API函数RegisterServiceProcess实现。 <br>二、定义全局热键(本例中定义热键Ctrl+Del+R),步骤: <br>1、定义捕获Windows消息WM_HOTKEY的钩子函数,即: <br>procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY; <br>2、向Windows加入一个全局原子 Myhotkey: GlobalAddAtom(’MyHotkey’), <br>并保留其句柄。 <br>3、向Windows登记热键:调用API函数RegisterHotKey实现。 <br>三、源程序: <br><br><br><br>unit Unit1; <br>interface <br>uses <br>Windows, Messages, Forms, Dialogs, Classes, Controls, StdCtrls; <br>type <br>TForm1 = class(TForm) <br>Button1: TButton; <br>Button2: TButton; <br>procedure FormCreate(Sender: TObject); <br>procedure Button1Click(Sender: TObject); <br>procedure Button2Click(Sender: TObject); <br>procedure FormClose(Sender: TObject; var Action: TCloseAction); <br>private <br>{热键标识ID} <br>id: Integer; <br>procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY; <br>{ Privat-Declarations} <br>public <br>{ Public-Declarations} <br>end; <br>var <br>Form1 : TForm1; <br>implementation <br>const RSP_SIMPLE_SERVICE=1; <br>function RegisterServiceProcess (dwProcessID, dwType: DWord) : DWord; stdcall; external ’KERNEL32.DLL’; <br>{$R *.DFM} <br><br>{捕获热键消息} <br>procedure TForm1.WMHotKey (var Msg : TWMHotKey); <br>begin <br>if msg.HotKey = id then <br>ShowMessage(’Ctrl+Alt+R键被按下!’); <br>form1.Visible :=true; <br>end; <br><br>procedure TForm1.FormCreate(Sender: TObject); <br>Const <br>{ALT、CTRL和R键的虚拟键值} <br>MOD_ALT = 1; <br>MOD_CONTROL = 2; <br>VK_R = 82; <br>begin <br>{首先判断程序是否已经运行} <br>if GlobalFindAtom(’MyHotkey’) = 0 then <br>begin <br>{注册全局热键Ctrl + Alt + R} <br>id:=GlobalAddAtom(’MyHotkey’); <br>RegisterHotKey(handle,id,MOD_CONTROL+MOD_Alt,VK_R); <br>end <br>else <br>halt; <br>end; <br><br>{把当前进程变为一个系统服务,从而在任务列表中把程序隐藏起来} <br>procedure TForm1.Button1Click(Sender: TObject); <br>begin <br>RegisterServiceProcess(GetCurrentProcessID,RSP_SIMPLE_SERVICE); <br>form1.Hide; <br>end; <br><br>procedure TForm1.Button2Click(Sender: TObject); <br>begin <br>close; <br>end; <br>{退出时释放全局热键} <br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); <br>begin <br>UnRegisterHotKey(handle,id); <br>GlobalDeleteAtom(id); <br>end; <br>end. <br>四、说明: <br>在后台监控软件中使用以上功能,可真正实现隐蔽运行,热键调出,便于管理员进行管理。程序在Win98,Delphi5.0中运行通过。