home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 11
/
Freelog011.iso
/
BestOf
/
PhoenixMail
/
Source
/
comps
/
FlyOverControl.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1999-01-06
|
5KB
|
148 lines
{*****************************************************************************
*
* FlyOverControl.pas - TFlyOverControl Component
*
* Copyright (c) 1998-99 Michael Haller
*
* Author: Michael Haller
* E-mail: michael@discountdrive.com
* Homepage: http://www.discountdrive.com/sunrise/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
*----------------------------------------------------------------------------
*
* Revision history:
*
* DATE REV DESCRIPTION
* ----------- --- ----------------------------------------------------------
*
*****************************************************************************}
unit FlyOverControl;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TOnControlChangeEvent = procedure(Sender: TObject; Control: TControl) of object;
TFlyOverControl = class(TComponent)
private
FOnControlChange: TOnControlChangeEvent;
MyOwner: TForm;
MyTimer: TTimer;
OldControl: TControl;
ControlList: array[1..200] of TControl;
HandleList: array[1..200] of HWnd;
ControlListCount: Integer;
procedure ListControls(WinControl: TWinControl);
procedure OnTimer(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property OnControlChange: TOnControlChangeEvent read FOnControlChange write FOnControlChange;
end;
procedure Register;
implementation
procedure TFlyOverControl.ListControls(WinControl: TWinControl);
procedure LCRecursive(WinControl: TWinControl);
var
I: Integer;
begin
for I := 0 to WinControl.ControlCount-1 do
if WinControl.Controls[I] is TWinControl then begin
Inc(ControlListCount);
if ControlListCount > 200 then raise Exception.Create('TFlyOverComponent: Too many controls!');
ControlList[ControlListCount] := WinControl.Controls[I];
HandleList[ControlListCount] := TWinControl(WinControl.Controls[I]).Handle;
if WinControl.Controls[I] is TWinControl then
if TWinControl(WinControl.Controls[I]).ControlCount > 0 then
LCRecursive(TWinControl(WinControl.Controls[I]));
end;
end;
begin
ControlListCount := 1;
ControlList[1] := WinControl;
HandleList[1] := WinControl.Handle;
LCRecursive(WinControl);
end;
constructor TFlyOverControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
with AOwner as TForm do MyOwner := TForm(AOwner);
ListControls(MyOwner);
OldControl := nil;
MyTimer := TTimer.Create(Self);
MyTimer.Interval := 10;
MyTimer.OnTimer := OnTimer;
end;
destructor TFlyOverControl.Destroy;
begin
MyTimer.Free;
inherited Destroy;
end;
function PointInRect(P: TPoint; R: TRect): Boolean;
begin
Result := False;
if (P.X >= R.Left) and (P.X <= R.Right) and (P.Y >= R.Top) and (P.Y <= R.Bottom) then Result := True;
end;
procedure TFlyOverControl.OnTimer(Sender: TObject);
var
P, P1: TPoint;
H: HWnd;
I: Integer;
W, C: TControl;
begin
GetCursorPos(P);
P1 := MyOwner.ScreenToClient(P);
if PointInRect(P1, MyOwner.ClientRect) then begin
H := WindowFromPoint(P);
W := nil;
if ControlListCount = 0 then Exit;
for I := 1 to ControlListCount do begin
if HandleList[I] = H then begin
W := ControlList[I];
Break;
end;
end;
if not Assigned(W) then Exit;
P := W.ScreenToClient(P);
C := TWinControl(W).ControlAtPos(P, False);
if C = nil then C := W;
end else
C := nil;
if OldControl = C then Exit;
OldControl := C;
if Assigned(FOnControlChange) then FOnControlChange(Self, C);
end;
procedure Register;
begin
RegisterComponents('Michael Haller', [TFlyOverControl]);
end;
end.