程序路径相同,只能运行一个进程(重复运行激活界面)

unit Unit1;


interface


uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,md5, StdCtrls ;


type
  TSanSvcFrm = class(TForm)
    chk1: TCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure chk1Click(Sender: TObject);
  private
    { Private declarations }
    
     procedure WndProc(var Message: TMessage); override;
  public
    { Public declarations }
    INTERMSG : UINT;
  end;


var
  SanSvcFrm: TSanSvcFrm;
  IsActiveExe:Boolean;
  XServerName, PathMd5:string;


implementation


{$R *.dfm}




procedure TSanSvcFrm.WndProc(var Message: TMessage);
var
  FWinfo: TFlashWInfo;
begin
  if (IsActiveExe) and (Message.Msg = INTERMSG) then
  begin
    if Message.WParam = $E218 then
    begin
       self.Show;
       Application.Restore;
       SetForegroundWindow(Application.Handle);
       ShowWindow(Application.Handle, SW_SHOW);
       FWinfo.cbSize := 20;
       FWinfo.hwnd := Application.Handle; // 闪烁窗口的句柄
       FWinfo.dwflags := FLASHW_ALL;
       FWinfo.ucount := 1;                // 闪烁的次数
       FWinfo.dwtimeout := 0;             // 速度以毫秒为单位, 0 默认为与指针闪烁的速率相同
       FlashWindowEx(FWinfo);             // 使它闪烁!
    end
  end else inherited;
end;


procedure TSanSvcFrm.chk1Click(Sender: TObject);
begin
  if chk1.Checked  then
  begin
     //这里安装服务  已 XServerName  做为服务名称。
  end else begin
    //这里删除服务.
  end;
end;


procedure TSanSvcFrm.FormCreate(Sender: TObject);
var
  TestHandle, Mutex: THandle;
begin
  IsActiveExe:=False;
  INTERMSG := RegisterWindowMessage(PChar(PathMd5));
  PathMd5:= RivestStr  (UpperCase(ParamStr(0)),0,32 );
  Mutex := CreateMutex(nil, True, PChar('SAN_'+PathMd5));
  if Mutex <> 0 then
  begin
    if GetLastError = Windows.ERROR_ALREADY_EXISTS then //如果存在另一实例
    begin
      Application.ShowMainForm :=False;
      Closehandle(Mutex);
      SendMessage(HWND_BROADCAST, INTERMSG, $E218, 0);
      ExitProcess(0);
      Exit;
    end;
  end;
  IsActiveExe:=True;
  XServerName:='SanSve'+PathMd5;
end;


end.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值