begin
GlobalMsg:=RegisterWindowMessage(PChar('文正明分机管理器已经运行'));
HMutex:=CreateMutex(nil,False,PChar('pwzmUsrMgr'));
if WaitForSingleObject(HMutex,100)=WAIT_TIMEOUT then
PostMessage(HWND_BROADCAST,GlobalMsg,0,0)
else
begin
Application.Initialize;
Application.Title := '分机管理器';
Application.CreateForm(TFrmMainStation, FrmMainStation);
Application.Run;
ReleaseMutex(HMutex);
end;
CloseHandle(HMutex);
end.
主窗口.pas
var
FrmMainStation: TFrmMainStation;
GlobalMsg: UINT;
procedure TFrmMainStation.OnAppMessage(var Msg:TMsg; Var Handled:Boolean);
begin
if Msg.message=GlobalMsg then
begin
Show;
WindowState:=wsNormal;
BringToFront;
SetFocus;
Handled:=True;
end;
end;
procedure TFrmMainStation.FormCreate(Sender: TObject);
begin
Application.OnMessage:=OnAppMessage;
end;