Holas. Necesito una ayuda. Estoy tratando de hacer un componente devirado de un TEdit, TKEdit, el cual, entre otras cosas, deberia habilitarme barras flotantes. Estuve viendo un ejemplo de nuestro amigo Neftali.
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Label2Click(Sender: TObject);
procedure FormResize(Sender: TObject);
private
procedure WMWindowPosChanging(var Message: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
procedure WMNCLButtonDown(var Message: TWMNCLButtonDown); message WM_NCLBUTTONDOWN;
procedure _MoveFW();
public
end;
var
Form1: TForm1;
implementation
uses Unit2, Unit3, ShellAPI;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Visible := not Form2.Visible;
Form3.Visible := not Form3.Visible;
_MoveFW();
end;
procedure TForm1.WMWindowPosChanging(var Message: TWMWindowPosChanging);
begin
_MoveFW();
inherited;
end;
procedure TForm1.Label2Click(Sender: TObject);
begin
ShellExecute(Handle,
'open',
'http://neftali.clubdelphi.com/',
nil,
nil,
SW_SHOW);
end;
procedure TForm1.WMNCLButtonDown(var Message: TWMNCLButtonDown);
begin
_MoveFW();
inherited;
end;
procedure TForm1._MoveFW;
begin
if not Assigned(Form2) then begin
Exit;
end;
if not Assigned(Form3) then begin
Exit;
end;
if (Form2.Visible) then begin
Form2.Top := Self.Top - Form2.Height;
Form2.Left := Self.Left;
end;
if (Form3.Visible) then begin
Form3.Top := Self.Top;
Form3.Left := Self.LEft + Self.Width;
end;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
_MoveFW();
end;
end.
Form2 y Form3 son las barras flotantes y este ejemplo funciona a la perfeccion.
¿Como hago para asignarle desde el TKEdit los procedures WMWindowPosChanging, WMNCLButtonDown y FormResize al TForm que lo contiene?
El TKEdit esta mas o menos asi.
Código Delphi
[-]
unit UnitKEdit;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Messages, Forms;
type
TKEditi = class(TEdit)
private
procedure WMWindowPosChanging(var Message: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
procedure WMNCLButtonDown(var Message: TWMNCLButtonDown); message WM_NCLBUTTONDOWN;
procedure _MoveFW();
protected
public
constructor Create(AOwner : TComponent); override;
published
end;
procedure Register;
implementation
uses Unitbarra_horizontal, Unitbarra_vertical, ShellAPI;
procedure Register;
begin
RegisterComponents('customer', [TKEdit]);
end;
constructor TKEdit.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
barra_vertical:=Tbarra_vertical.Create(self);
barra_horizontal:=Tbarra_horizontal.Create(self);
barra_vertical.Visible:=true;
barra_horizontal.Visible:=true;
try
_MoveFW;
except
end;
end;
procedure TKEdit._MoveFW;
begin
if not Assigned(barra_vertical) then begin
Exit;
end;
if not Assigned(barra_horizontal) then begin
Exit;
end;
if (barra_vertical.Visible) then begin
barra_vertical.Top := Self.Parent.Top - barra_vertical.Height;
barra_vertical.Left := Self.Parent.Left;
end;
if (barra_horizontal.Visible) then begin
barra_horizontal.Top := Self.Parent.Top;
barra_horizontal.Left := Self.Parent.LEft + Self.Parent.Width;
end;
end;
procedure TKEdit.WMWindowPosChanging(var Message: TWMWindowPosChanging);
begin
_MoveFW();
inherited;
end;
procedure TKEdit.WMNCLButtonDown(var Message: TWMNCLButtonDown);
begin
_MoveFW();
inherited;
end;
end.
Gracias!