MID子窗体的实现代码如下:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
private
FHandleTaskBar : TCustomForm;
FT : HWND;
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
Type
TTaskbarForm = class(TCustomForm)
private
FMDIChild : TCustomForm;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure WndProc(var Message: TMessage); override;
public
constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); override;
end;
{ TForm2 }
constructor TForm2.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FHandleTaskBar := TTaskbarForm.CreateNew(Self);
FHandleTaskBar.Show;
end;
destructor TForm2.Destroy;
begin
FHandleTaskBar.Free;
inherited Destroy;
end;
{ TTaskbarForm }
constructor TTaskbarForm.CreateNew(AOwner: TComponent; Dummy: Integer);
begin
inherited CreateNew(AOwner);
FMDIChild := TCustomForm(AOwner);
Caption := FMDIChild.Caption;
BorderStyle := bsNone;
Height := 0;
Width := 0;
end;
procedure TTaskbarForm.CreateParams(var Params: TCreateParams);
begin
Inherited CreateParams(Params);
With Params Do exStyle := exStyle Or WS_EX_APPWINDOW;
end;
procedure TTaskbarForm.WndProc(var Message: TMessage);
begin
case Message.Msg of
WM_ACTIVATE,
WM_SETFOCUS,
WM_KILLFOCUS,
WM_APP,
WM_APPCOMMAND,
WM_SYSCOMMAND:
begin
FMDIChild.Perform(Message.Msg, Message.WParam, Message.LParam);
end;
else
inherited WndProc( Message);
end;
end;
end.