// 当鼠标离开客户区时隐藏unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) btn1: TButton; procedure btn1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure FormCreate(Sender: TObject); private public { Public declarations } end;var Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);begin if not Assigned(Form2) then begin Form2 := TForm2.Create(Self); Form2.Parent := Self; end; Form2.Show;end;procedure TForm1.FormDestroy(Sender: TObject);begin if Assigned(Form2) then FreeAndNil(Form2);end;procedure TForm1.FormCreate(Sender: TObject);begin// Self.FormStyle := fsMDIForm;end;end.// =======================================unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;type TForm2 = class(TForm) procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormCreate(Sender: TObject); procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private { Private declarations } FHasTrackMouse: Boolean; procedure WM_MouseLeave(var message: TMessage); message WM_MouseLeave; public { Public declarations } procedure NoTitleBoardMove; { Public declarations } end;var Form2: TForm2;implementation{$R *.dfm}procedure TForm2.WM_MouseLeave(var message: TMessage);begin inherited; Self.Hide; FHasTrackMouse := False;end;procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);begin Form2 := nil; Action := caFree;end;procedure TForm2.FormCreate(Sender: TObject);begin// Self.FormStyle := fsMDIChild; FHasTrackMouse := False;end;procedure TForm2.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);var a: tagTRACKMOUSEEVENT;begin if not FHasTrackMouse then begin a.cbSize := SizeOf(a); a.dwFlags := TME_LEAVE; a.hwndTrack := Self.Handle; // a.dwHoverTime := FHasTrackMouse := TrackMouseEvent(a); end;end;procedure TForm2.NoTitleBoardMove;begin ReleaseCapture; SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);end;procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin NoTitleBoardMove;end;end.