已启动程序,再启动通知原程序显示

来源:互联网 发布:五子棋最强软件 编辑:程序博客网 时间:2024/06/05 08:55
var
  YunTansuoHandle, Mutex: THandle;
begin
  Mutex := CreateMutex(nil, True, 'YunTansuoAppMain');
  if Mutex <> 0 then
  begin
    if GetLastError = Windows.ERROR_ALREADY_EXISTS then //如果存在另一实例
    begin
      Closehandle(Mutex);
      //找窗口,发消息,让其显示出来...
      YunTansuoHandle := FindWindow('TYunTansuo_Main_Frm', nil);
      if YunTansuoHandle <> 0 then
        PostMessage(YunTansuoHandle, WM_RUNME_MESSAGE, $E218, 0);
      ExitProcess(0);
      Exit;
    end;
  end;



const
  WM_RUNME_MESSAGE = WM_USER + 1000;

  private
    { Private declarations }

    procedure OnRunMeMessage(var msg: TMessage); message WM_RUNME_MESSAGE;

procedure T'YunTansuoAppMain'.OnRunMeMessage(var msg: TMessage);
var
  NewDemo: TForm;
begin //显示自己...
  if msg.WParam = $E218 then
  begin
    //
  end;
end;
0 0
原创粉丝点击