给你一个范例,如第二次则不能激活form<br>/////////////<br>program Project1;<br><br>uses<br> Forms, Windows,<br> Unit1 in 'Unit1.pas' {Form1};<br><br>var<br> Mutex: THandle;<br><br>{$R *.RES}<br><br>begin<br> Mutex := CreateMutex(NIL, True, 'Form1');<br> if GetLastError <> ERROR_ALREADY_EXISTS then<br> begin<br>// Application.Initialize;<br> Application.CreateHandle;<br> Application.CreateForm(TForm1, Form1);<br> Application.Run;<br> end;<br> ReleaseMutex(Mutex);<br>end.<br><br>///<br>unit Unit1; <br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls, ExtCtrls, Menus;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> procedure FormCreate(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> { Private declarations }<br> procedure WMHotKey(var Message:TMessage);message WM_HOTKEY;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.WMHotKey(var Message:TMessage);<br>var<br> AType: TMsgDlgType;<br> AButton: TMsgDlgButtons;<br> WResult: Word;<br>begin<br> AType := mtConfirmation;<br> AButton:= mbYesNoCancel;<br> WResult := MessageDlg('End of RUN?',AType,AButton,0);<br> if WResult= mrYes then<br> begin<br> Form1.Close;<br> Application.Terminate;<br> end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> // Alt+Control+A<br> if RegisterHotKey(Form1.handle,0,MOD_ALT OR MOD_CONTROL,65) then<br> ShowMessage('OK');<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> Form1.Hide;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> if UnRegisterHotKey(Form1.Handle,0) then<br> ShowMessage('IIOK');<br>end;<br><br>end.<br>