1 Star 0 Fork 25

Lyon/php_desktop

forked from lobtao/php_desktop 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
unRunOne.pas 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
lobtao 提交于 2018-08-22 11:32 . init
unit unRunOne;
interface
(* 程序是否已经运行,如果运行则激活它 *)
function AppHasRun(AppHandle: THandle; MapFileName: string): Boolean;
implementation
uses
Windows, Forms;
//const
// MapFileName = '{153CBD7A-C36B-4DB8-8163-2E5FE4C79E07}';
type
//共享内存
PShareMem = ^TShareMem;
TShareMem = record
AppHandle: THandle; //保存程序的句柄
end;
var
hMapFile: THandle;
PSMem: PShareMem;
procedure CreateMapFile(MapFileName: string);
begin
hMapFile := OpenFileMapping(FILE_MAP_ALL_ACCESS, False, PChar(MapFileName));
if hMapFile = 0 then
begin
hMapFile := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0,
SizeOf(TShareMem), PChar(MapFileName));
PSMem := MapViewOfFile(hMapFile, FILE_MAP_WRITE or FILE_MAP_READ, 0, 0, 0);
if PSMem = nil then
begin
CloseHandle(hMapFile);
Exit;
end;
PSMem^.AppHandle := 0;
end
else
begin
PSMem := MapViewOfFile(hMapFile, FILE_MAP_WRITE or FILE_MAP_READ, 0, 0, 0);
if PSMem = nil then
begin
CloseHandle(hMapFile);
end
end;
end;
procedure FreeMapFile;
begin
UnMapViewOfFile(PSMem);
CloseHandle(hMapFile);
end;
function AppHasRun(AppHandle: THandle; MapFileName: string): Boolean;
var
TopWindow: HWnd;
begin
//创建句柄
CreateMapFile(MapFileName);
Result := False;
if PSMem <> nil then
begin
if PSMem^.AppHandle <> 0 then
begin
// SendMessage(PSMem^.AppHandle, WM_SYSCOMMAND, SC_RESTORE, 0);
// TopWindow := GetLastActivePopup(PSMem^.AppHandle);
// if (TopWindow <> 0) and (TopWindow <> PSMem^.AppHandle) and
// IsWindowVisible(TopWindow) and IsWindowEnabled(TopWindow) then
// begin
// SetForegroundWindow(TopWindow);
// end;
MessageBox(0, '该程序已经运行中!','远思应用服务器', MB_OK+MB_ICONINFORMATION);
Application.Terminate;
Result := True;
end
else
PSMem^.AppHandle := AppHandle;
end;
end;
initialization
// CreateMapFile;
finalization
FreeMapFile;
end.
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/LyonH/php_desktop.git
git@gitee.com:LyonH/php_desktop.git
LyonH
php_desktop
php_desktop
master

搜索帮助