unit RW_FormPanel;
interface
uses
Forms, Windows, Messages, Classes, Controls, ExtCtrls;
type
TRWFormPanel =
class(TCustomPanel)
private
FForm: TCustomForm;
FFormSaveParent: THandle;
FFormSavePosition: TPosition;
FFormSaveStyle: Integer;
FFormSaveStyleEx: Integer;
FFormSaveVisible: Boolean;
FFormSaveWindowPlacement: TWindowPlacement;
procedure SetForm(Value:TCustomForm);
protected
procedure Notification(AComponent : TComponent; Operation : TOperation);
override;
procedure SizeChanged;
procedure WMSize(
var Message:TMessage);
message WM_SIZE;
public
constructor Create(AOwner:TComponent);
override;
property Form: TCustomForm
read FForm
write SetForm;
published
property Align;
property Alignment;
property Anchors;
property AutoSize;
property BevelInner;
property BevelOuter
default bvNone;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property BorderWidth;
property Caption;
property Color;
property Constraints;
property Ctl3D;
property DockSite;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property FullRepaint;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnDblClick;
property OnDockDrop;
property OnDockOver;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property UseDockManager
default True;
property Visible;
end;
implementation
procedure TRWFormPanel.Notification(AComponent : TComponent; Operation :
TOperation);
begin
inherited Notification( AComponent, Operation);
if Assigned(FForm)
then
if (Operation = opRemove)
and (AComponent = FForm)
then
begin
// RemoveFreeNotification(AComponent);
FForm :=
nil;
end;
end;
procedure TRWFormPanel.SetForm(Value:TCustomForm);
begin
try
if (FForm = Value)
then
Exit;
if csDesigning
in ComponentState
then
Exit;
// hat schon ein Form, also wiederherstellen
if (FForm<>
nil)
and FForm.HandleAllocated
then
begin
FForm.Visible := False;
if not FFormSaveVisible
then
FFormSaveWindowPlacement.showCmd:=SW_HIDE;
Windows.SetParent(FForm.Handle,FFormSaveParent);
SetWindowPlacement(FForm.Handle,@FFormSaveWindowPlacement);
SetWindowLong(FForm.Handle,GWL_STYLE,FFormSaveStyle);
SetWindowLong(FForm.Handle,GWL_EXSTYLE,FFormSaveStyleEx);
SetWindowPos(FForm.Handle,HWND_BOTTOM,0,0,0,0,SWP_NOMOVE
or SWP_NOSIZE
or
SWP_NOZORDER
or SWP_FRAMECHANGED
or SWP_NOACTIVATE);
FForm.Visible := FFormSaveVisible;
TForm(FForm).Position := FFormSavePosition;
end;
FForm:=Value;
if FForm<>
nil then
begin
FFormSaveStyle := GetWindowLong(FForm.Handle,GWL_STYLE);
FFormSaveStyleEx := GetWindowLong(FForm.Handle,GWL_EXSTYLE);
FFormSaveVisible := FForm.Visible;
FFormSaveParent := GetParent(FForm.Handle);
FFormSavePosition := TForm(FForm).Position;
TForm(FForm).Position := poDesigned;
GetWindowPlacement(FForm.Handle,@FFormSaveWindowPlacement);
SetWindowLong(FForm.Handle,GWL_STYLE,(FFormSaveStyle
or WS_CHILD)
and not WS_OVERLAPPED
and not WS_OVERLAPPEDWINDOW
and not WS_CAPTION);
SetWindowLong(FForm.Handle,GWL_EXSTYLE,FFormSaveStyleEx
and not WS_EX_MDICHILD);
Windows.SetParent(FForm.Handle,self.Handle);
SetWindowPos(FForm.Handle,HWND_BOTTOM,0,0,0,0,SWP_NOMOVE
or SWP_NOSIZE
or
SWP_NOZORDER
or SWP_FRAMECHANGED
or SWP_NOACTIVATE);
FForm.Left:=0;
FForm.Top:=0;
SizeChanged;
// FForm.Visible:=True;
// FForm.SetFocus;
// Application.ProcessMessages;
FForm.FreeNotification(Self);
end;
except
FForm :=
nil;
if csLoading
in ComponentState
then
Application.HandleException(Self)
else
raise;
end;
end;
procedure TRWFormPanel.SizeChanged;
begin
FForm.Width := ClientWidth;
FForm.Height := ClientHeight;
end;
procedure TRWFormPanel.WMSize(
Var Message:TMessage);
begin
inherited;
if FForm <>
nil then
SizeChanged;
end;
constructor TRWFormPanel.Create(AOwner:TComponent);
begin
inherited;
// BevelOuter := bvNone;
Caption := '
';
end;
end.