⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 previnst.pas

📁 siMail, siMail, siMail, siMail
💻 PAS
字号:
(*
# (C) Copyright 2003
# Miha Vrhovnik, miha.vrhovnik@cordia.si
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
# The Initial Developer of the Original Code is Miha Vrhovnik (Slovenia).
# Portions created by Miha Vrhovnik are Copyright (c)2003.
# All Rights Reserved.
#==============================================================================
# Contributor(s):
#==============================================================================
# History: see whats new.txt from distribution package
#==============================================================================
*)
unit prevInst;

interface

procedure PreviousInstance(appName: String);
var mainWindowHWND: PInteger;

implementation

uses SysUtils, Windows, Forms, Messages, Classes;

var mapHandle: THandle;

//this code sends current instance commandline parameters to previous instance
procedure PreviousInstance(appName: String);
var name:String;
var cs: PCopyDataStruct;
var sl: TStringList;
var i: Integer;
begin
  name := StringReplace(appName, ':', '', [rfReplaceAll]);
  name := StringReplace(name, '\', '', [rfReplaceAll]);

  mapHandle := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0,
      sizeOf(Integer), PChar(name));

  if mapHandle = 0 then
    RaiseLastOSError
  else if GetLastError <> ERROR_ALREADY_EXISTS then begin
        mainWindowHWND := MapViewOfFile(mapHandle, FILE_MAP_ALL_ACCESS,
            0, 0, SizeOf(mainWindowHWND));
  end
  else begin //file exists
        mainWindowHWND := MapViewOfFile(mapHandle, FILE_MAP_ALL_ACCESS,
            0, 0, SizeOf(mainWindowHWND));
    //send commandline
    GetMem(cs, sizeOf(TCopyDataStruct));
    sl := TStringList.Create;
    try
      if ParamCount > 0 then begin
        for i := 1 to ParamCount do
          sl.Add(ParamStr(i))
      end
      else
        sl.Add('/Restore');
    finally
      name := sl.Text;
      sl.Free;
    end;

    with cs^ do begin
      dwData := 0;
      cbData := Length(name);
      lpData := PChar(name);
    end;

    SendMessage(mainWindowHWND^, WM_COPYDATA, Application.Handle, Integer(cs));
    FreeMem(cs);
  end;

end;

initialization
finalization
  UnmapViewOfFile(mainWindowHWND);
  CloseHandle(mapHandle);
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -