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

📄 onceonly.pas

📁 PatientRunner 20 Source
💻 PAS
字号:
{ *************************************************************************** }
{                                                                             }
{ PatientRunner                                                               }
{                                                                             }
{ Copyright (c) 2002-2003 IgD Software, LLC                                   }
{                                                                             }
{ This file may be distributed and/or modified under the terms of the GNU     }
{ General Public License (GPL) version 2 as published by the Free Software    }
{ Foundation and appearing at http://www.gnu.org/licenses/gpl.html.           }
{                                                                             }
{ *************************************************************************** }

unit OnceOnly;

interface

function AlreadyRunning( const AppTitle: String ): Boolean;

implementation

uses Messages, Windows, Sysutils;

var mutex: THandle = 0;

{ *************************************************************************** }
{                                                                             }
{ function AlreadyRunning                                                     }
{                                                                             }
{ This function tests to see if another instance of the application is        }
{ already running and returns a boolean.  If another instance is detected,    }
{ the function will try to bring it to the front.                             }
{                                                                             }
{ Adapted fromPeter Below's public domain code from Borland newsgroups        }
{ *************************************************************************** }

function AlreadyRunning(const AppTitle: String): Boolean;
var wnd: HWND;
begin { AlreadyRunning }
  mutex := CreateMutex( nil, false,
                        PChar( StringReplace(AppTitle, ' ', '_',
                                            [rfReplaceAll] )));
  if mutex = 0 then
    Result := false
  else
    Result := GetLastError = ERROR_ALREADY_EXISTS;

  if Result then
  begin
    wnd:= FindWindow( 'TApplication', PChar( AppTitle ));
    if wnd <> 0 Then
    begin
      if IsIconic(wnd) then SendMessage( wnd, WM_SYSCOMMAND, SC_RESTORE, 0 );
      SetForegroundWindow( wnd );
    End; { If }
  End; { If }
End; { AlreadyRunning }

initialization

finalization
  if mutex <> 0 Then CloseHandle( mutex );

end.

⌨️ 快捷键说明

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