home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kolekce / d56 / TDSOFT.ZIP / TDTrasparentWindow.pas < prev    next >
Pascal/Delphi Source File  |  2001-05-24  |  4KB  |  159 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       TDSoft Visual Component Library                 }
  4. {                                                       }
  5. {       Copyright (c) 2001 Daniele Teti                 }
  6. {                                                       }
  7. {-------------------------------------------------------}
  8. {       For suggest, request, bug or only for sport:    }
  9. {       Daniele_Teti@hotmail.com                        }
  10. {-------------------------------------------------------}
  11. {                                                       }
  12. {  N.B Features available only in Windows 2000          }
  13. {*******************************************************}
  14.  
  15. unit TDTrasparentWindow;
  16.  
  17. interface
  18.  
  19. uses
  20.   Dialogs,Windows, SysUtils, Classes, Forms,DsgnIntf;
  21.  
  22. {$R *.DCR}
  23.  
  24. type
  25.   TTDTrasparentWindow = class(TComponent)
  26.   private
  27.     FDelay: Cardinal;
  28.     procedure SetDelay(const Value: Cardinal);
  29.     function GetAbout: string;
  30.     procedure SetAbout(const Value: string);
  31.     { Private declarations }
  32.   protected
  33.     { Protected declarations }
  34.   public
  35.     { Public declarations }
  36.     function ShowTrasparent: LongBool; OverLoad;
  37.     function ShowTrasparent(Time: Cardinal): LongBool; OverLoad;
  38.  
  39.     function HideTrasparent: LongBool; OverLoad;
  40.     function HideTrasparent(Time: Cardinal): LongBool; OverLoad;
  41.  
  42.   published
  43.     { Published declarations }
  44.     property Delay: Cardinal read FDelay write SetDelay;
  45.     property About: string read GetAbout write SetAbout stored False;
  46.   end;
  47.  
  48. TAboutProperty = class(TStringProperty)
  49.   public
  50.     function GetAttributes: TPropertyAttributes; override;
  51.     procedure Edit; override;
  52.   end;
  53.  
  54.  
  55. procedure Register;
  56.  
  57. implementation
  58.  
  59. type EParentIsNotAForm=class(Exception);
  60.  
  61. function TAboutProperty.GetAttributes: TPropertyAttributes;
  62. begin
  63.   Result := [paDialog];
  64. end;
  65.  
  66.  
  67. procedure TAboutProperty.Edit;
  68. begin
  69.   MessageDlg('TTDTrasparentWindow 0.8b' + #13 + '(30/Dic/2000)' + #13 + #13 +
  70.     'written by Teti Daniele (Daniele_Teti@Hotmail.com)', mtInformation, [mbOk], 0);
  71. end;
  72.  
  73.  
  74.  
  75. procedure Register;
  76. begin
  77.   RegisterComponents('TDSoft', [TTDTrasparentWindow]);
  78.   RegisterPropertyEditor(TypeInfo(string), TTDTrasparentWindow, 'About', TAboutProperty);
  79. end;
  80.  
  81. { TTDTrasparentWindow }
  82.  
  83.  
  84. function TTDTrasparentWindow.HideTrasparent: LongBool;
  85. var
  86.   OwnerForm: TForm;
  87.  
  88. begin
  89.   Result:=False; //Solo x evitare gli WARNINGS 'HO GIA PROVATO CON LE DIRETTIVE AL COMPILATORE'!!!
  90.  
  91.   if not(GetOwner is TForm) then
  92.     raise EParentIsNotAForm.Create('Owner component is not a TForm descendant');
  93.  
  94.     try
  95.       OwnerForm:=TForm(GetOwner);
  96.       SetActiveWindow(OwnerForm.handle);
  97.       Result:=AnimateWindow(TForm(OwnerForm).handle,FDelay,AW_BLEND or AW_CENTER or AW_HIDE);
  98.       TForm(OwnerForm).Close;
  99.     except
  100.       if not(GetOwner is TForm) then
  101.         raise Exception.Create('InternalError.');
  102.     end;
  103. end;
  104.  
  105.  
  106. function TTDTrasparentWindow.GetAbout: string;
  107. begin
  108.   Result:='TDSoft (c) Teti Daniele Component';
  109. end;
  110.  
  111. function TTDTrasparentWindow.HideTrasparent(Time: Cardinal): LongBool;
  112. begin
  113.   SetDelay(Time);
  114.   Result:=HideTrasparent;
  115. end;
  116.  
  117.  
  118. procedure TTDTrasparentWindow.SetDelay(const Value: Cardinal);
  119. begin
  120.   FDelay := Value;
  121. end;
  122.  
  123. function TTDTrasparentWindow.ShowTrasparent: LongBool;
  124. var
  125.   OwnerForm: TForm;
  126.  
  127. begin
  128.   Result:=False; //Solo x evitare gli WARNINGS 'HO GIA PROVATO CON LE DIRETTIVE AL COMPILATORE'!!!
  129.  
  130.   if not(GetOwner is TForm) then
  131.     raise EParentIsNotAForm.Create('Owner component is not a TForm descendant');
  132.  
  133.     try
  134.       OwnerForm:=TForm(GetOwner);
  135.       SetActiveWindow(OwnerForm.handle);
  136.       Result:=AnimateWindow(TForm(OwnerForm).handle,FDelay,AW_BLEND or AW_CENTER or AW_ACTIVATE);
  137.       TForm(OwnerForm).Show;
  138.       TForm(OwnerForm).Invalidate;
  139.     except
  140.       if not(GetOwner is TForm) then
  141.         raise Exception.Create('InternalError.');
  142.     end;
  143. end;
  144.  
  145. function TTDTrasparentWindow.ShowTrasparent(Time: Cardinal): LongBool;
  146. begin
  147.   SetDelay(Time);
  148.   Result:=ShowTrasparent;
  149. end;
  150.  
  151.  
  152.  
  153. procedure TTDTrasparentWindow.SetAbout(const Value: string);
  154. begin
  155.   //Just for Syntax
  156. end;
  157.  
  158. end.
  159.