program Previns;
uses
WinTypes,
WinProcs,
SysUtils,
Forms,
Uprevins in 'UPREVINS.PAS' {Form1};
{$R *.RES}
type PHWND = ^HWND; function EnumFunc(Wnd:HWND; TargetWindow:PHWND): bool; export; var ClassName : array[0..30] of char; begin Result := true; if GetWindowWord(Wnd,GWW_HINSTANCE) = hPrevInst then begin GetClassName( Wnd, ClassName, 30 ); if StrIComp( ClassName, 'TApplication' ) = 0 then begin TargetWindow^ := Wnd; Result := false; end; end; end; procedure GotoPreviousInstance; var PrevInstWnd : HWND; begin PrevInstWnd := 0; EnumWindows( @EnumFunc, Longint( @PrevInstWnd ) ); if PrevInstWnd <> 0 then if IsIconic( PrevInstWnd ) then ShowWindow( PrevInstWnd, SW_RESTORE ) else BringWindowToTop( PrevInstWnd ); end; begin if hPrevInst <> 0 then GotoPreviousInstance else begin Application.CreateForm(TForm1, Form1); Application.Run; end; end. |