OneInst.pas
资源名称:srmsrc.zip [点击查看]
上传用户:tj00001
上传日期:2007-01-07
资源大小:672k
文件大小:1k
源码类别:
行业应用
开发平台:
Delphi
- unit OneInst;
- interface
- uses
- Windows, SysUtils, Forms;
- function CheckInstance:boolean;
- implementation
- var
- MyAppName, MyClassName: array[0..255] of Char;
- NumFound: Integer;
- LastFound, MyPopup: HWND;
- function LookAtAllWindows(Handle: HWND; Temp: LongInt): BOOL; stdcall;
- var
- WindowName, ClassName: Array[0..255] of Char;
- begin
- if (GetClassName(Handle, ClassName, SizeOf(ClassName)) > 0) and
- (StrComp(ClassName, MyClassName) = 0) and
- (GetWindowText(Handle, WindowName, SizeOf(WindowName)) > 0) and
- (StrComp(WindowName, MyAppName) = 0) then
- begin
- Inc(NumFound);
- if Handle <> Application.Handle then LastFound := Handle;
- end;
- Result:= True;
- end;
- function CheckInstance:boolean;
- begin
- Result:=false;
- NumFound := 0;
- LastFound := 0;
- GetWindowText(Application.Handle, MyAppName, SizeOf(MyAppName));
- GetClassName(Application.Handle, MyClassName, SizeOf(MyClassName));
- EnumWindows(@LookAtAllWindows, 0);
- if NumFound> 1 then
- begin
- MyPopup := GetLastActivePopup(LastFound);
- BringWindowToTop(LastFound);
- if IsIconic(MyPopup)
- then ShowWindow(MyPopup, SW_RESTORE)
- else SetForegroundWindow(MyPopup);
- Application.Terminate;
- Result:=true;
- end
- end;
- end.