// ==========================================================================================
// Version : V1.0
// Author : Jfyes
// Create by : 2005-01-21
// Function : 运行一个程序实例, 如果存在原有的实例将其恢复为Windows 活动窗口
// IDE: Delphi 6.0 and Win2000
var
MyAppName,
MyClassName: array[0..255] of Char;
NumFound: Integer;
LastFound, MyPopup: HWND;
procedure TTaiShing.ChkWindow;
function ChkAllWindows(Handle: HWND; Temp: LongInt): BOOL; stdcall;
var
WindowName,
ClassName: array[0..255] of Char;
begin
if GetClassName(Handle, ClassName, SizeOf(ClassName)) > 0 then
if StrComp(ClassName, MyClassName) = 0 then
if GetWindowText(Handle, WindowName, SizeOf(WindowName)) > 0 then
if StrComp(WindowName, MyAppName) = 0 then
begin
Inc(NumFound);
if Handle <> Application.Handle then
LastFound := Handle;
end;
result := true;
end;
begin
NumFound := 0;
LastFound := 0;
GetWindowText(Application.Handle, MyAppName, SizeOf(MyAppName));
GetClassName(Application.Handle, MyClassName, SizeOf(MyClassName));
EnumWindows(@ChkAllWindows, 0);
if NumFound > 1 then //不是一个窗口
begin
MyPopup := GetLastActivePopup(LastFound);
BringWindowToTop(LastFound);
if IsIconic(MyPopup) then
ShowWindow(MyPopup, SW_RESTORE)
else
SetForegroundWindow(MyPopup);
Halt;
end
end;
// end function 运行一个程序实例
//==========================================================================