home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Calmira / Src / UTILS / EXTFORM.PAS < prev    next >
Pascal/Delphi Source File  |  1997-02-15  |  3KB  |  109 lines

  1. {*********************************************************}
  2. {                                                         }
  3. {    Calmira System Library 1.0                           }
  4. {    by Li-Hsin Huang,                                    }
  5. {    released into the public domain January 1997         }
  6. {                                                         }
  7. {*********************************************************}
  8.  
  9. unit ExtForm;
  10.  
  11. { Extended Form unit.
  12.  
  13.   Defines TExtForm, which is a TForm with facilities for saving its
  14.   size and position.  The additional property MinPosition allows the
  15.   form to appear as an icon at a specified position (i.e., setting
  16.   it also shows the form).
  17. }
  18.  
  19. interface
  20.  
  21. uses Forms, WinTypes, IniFiles, Messages;
  22.  
  23. type
  24.   TExtForm = class(TForm)
  25.   private
  26.     FLastMinPosition : TPoint;
  27.     function GetMinPosition: TPoint;
  28.     procedure SetMinPosition(pt: TPoint);
  29.   public
  30.     procedure ShowNormal;
  31.     procedure SavePosition(ini : TIniFile; const section : string);
  32.     procedure LoadPosition(ini : TIniFile; const section : string);
  33.     property MinPosition: TPoint read GetMinPosition write SetMinPosition;
  34.     property LastMinPosition : TPoint read FLastMinPosition;
  35.   end;
  36.  
  37.  
  38. implementation
  39.  
  40. uses WinProcs, Classes;
  41.  
  42. function TExtForm.GetMinPosition: TPoint;
  43. var place: TWindowPlacement;
  44. begin
  45.   place.Length := sizeof(place);
  46.   GetWindowPlacement(Handle, @place);
  47.   Result := place.ptMinPosition;
  48. end;
  49.  
  50.  
  51. procedure TExtForm.SetMinPosition(pt: TPoint);
  52. var place: TWindowPlacement;
  53. begin
  54.   with Screen do begin
  55.     if pt.x >= Width then pt.x := Width - 48;
  56.     if pt.y >= Height then pt.y := Height - 48;
  57.   end;
  58.  
  59.   if Visible then Invalidate;
  60.   place.Length := sizeof(place);
  61.   GetWindowPlacement(Handle, @place);
  62.   place.ptMinPosition := pt;
  63.   place.Flags := place.Flags or WPF_SETMINPOSITION;
  64.   place.ShowCmd := SW_SHOWMINNOACTIVE;
  65.   SetWindowPlacement(Handle, @place);
  66.   Visible := True;
  67.   FLastMinPosition := pt;
  68. end;
  69.  
  70.  
  71. procedure TExtForm.SavePosition(ini : TIniFile; const section: string);
  72. begin
  73.   with ini do begin
  74.     WriteInteger(section, 'Left', Left);
  75.     WriteInteger(section, 'Top', Top);
  76.     WriteInteger(section, 'Width', Width);
  77.     WriteInteger(section, 'Height', Height);
  78.  
  79.     with MinPosition do begin
  80.       WriteInteger(section, 'MinLeft', X);
  81.       WriteInteger(section, 'MinTop', Y);
  82.     end;
  83.   end;
  84. end;
  85.  
  86. procedure TExtForm.LoadPosition(ini : TIniFile; const section : string);
  87. begin
  88.   with ini do begin
  89.   MinPosition := Point(ReadInteger(section, 'MinLeft', 128),
  90.                        ReadInteger(section, 'MinTop', 128));
  91.  
  92.   SetBounds(ReadInteger(section, 'Left', 0),
  93.             ReadInteger(section, 'Top', 0),
  94.             ReadInteger(section, 'Width', 256),
  95.             ReadInteger(section, 'Height', 256));
  96.   end;
  97. end;
  98.  
  99. procedure TExtForm.ShowNormal;
  100. begin
  101.   WindowState := wsNormal;
  102.   Show;
  103. end;
  104.  
  105.  
  106.  
  107.  
  108. end.
  109.