home *** CD-ROM | disk | FTP | other *** search
/ Computerworld 1996 March / Computerworld_1996-03_cd.bin / idg_cd3 / utility / applau13 / previnst.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-14  |  895 b   |  43 lines

  1. unit PrevInst;
  2.  
  3. interface
  4.  
  5. uses WinProcs, WinTypes, SysUtils;
  6.  
  7. type
  8.   PHWnd = ^HWnd;
  9.  
  10. function EnumFunc(Wnd : HWnd; TargetWindow : PHWnd): Bool; export;
  11. procedure ActivatePreviousInstance;
  12.  
  13. implementation
  14.  
  15. function EnumFunc(Wnd : HWnd; TargetWindow : PHWnd): Bool;
  16. var
  17.   ClassName : array [0..30] of char;
  18. begin
  19.   Result := True;
  20.   if GetWindowWord(Wnd,GWW_HINSTANCE) = HPrevInst then begin
  21.     GetClassName(Wnd,ClassName,30);
  22.     if StrIComp(ClassName,'TApplication') = 0 then begin
  23.       TargetWindow^ := Wnd;
  24.       Result := False;
  25.     end;
  26.   end;
  27. end;
  28.  
  29. procedure ActivatePreviousInstance;
  30. var
  31.   PrevInstWnd : HWnd;
  32. begin
  33.   PrevInstWnd := 0;
  34.   EnumWindows(@EnumFunc,Longint(@PrevInstWnd));
  35.   if PrevInstWnd <> 0 then
  36.     if IsIconic(PrevInstWnd) then      ShowWindow(PrevInstWnd,SW_RESTORE)
  37.     else
  38.       BringWindowToTop(PrevInstWnd);
  39. end;
  40.  
  41. end.
  42.  
  43.