我希望创建一个带有自己任务栏的MDI应用程序,以便用户可以快速访问要前置的子窗口。然后我想到了一个用户使用两个或多个显示器的想法,他可以将一个子窗口从我的应用程序的主窗体内部拖到外部,例如另一个监视器中。
如何实现?
如何实现?
unit Unit3;
interface
uses
Windows, Messages, Controls, Forms;
type
TForm3 = class(TForm)
private
FSizing: Boolean;
procedure WMNCMouseLeave(var Message: TMessage);
message WM_NCMOUSELEAVE;
procedure WMWindowPosChanged(var Message: TWMWindowPosChanged);
message WM_WINDOWPOSCHANGED;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure Resize; override;
end;
implementation
{$R *.dfm}
{ TForm3 }
var
FDragging: Boolean = False;
procedure TForm3.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
if FormStyle = fsNormal then
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW
else
Params.ExStyle := Params.ExStyle and not WS_EX_APPWINDOW;
end;
procedure TForm3.Resize;
begin
inherited Resize;
FSizing := True;
end;
procedure TForm3.WMNCMouseLeave(var Message: TMessage);
begin
inherited;
FDragging := False;
end;
procedure TForm3.WMWindowPosChanged(var Message: TWMWindowPosChanged);
var
P: TPoint;
F: TCustomForm;
R: TRect;
begin
inherited;
if not FDragging and not FSizing and not (fsShowing in FormState) and
(WindowState = wsNormal) then
begin
F := Application.MainForm;
P := F.ScreenToClient(Mouse.CursorPos);
R := F.ClientRect;
InflateRect(R, -5, -5);
if not PtInRect(R, P) and (FormStyle = fsMDIChild) then
begin
FDragging := True;
FormStyle := fsNormal;
Top := Top + F.Top;
Left := Left + F.Left;
end
else if PtInRect(R, P) and (FormStyle = fsNormal) then
begin
FDragging := True;
FormStyle := fsMDIChild;
end;
end;
FSizing := False;
end;
end.
WM_WINDOWPOSCHANGED
也会发送到所有其他窗体...请参见编辑。 - NGLN
ITaskbarList3
接口访问任务栏的支持。但是无法将 MDI 子窗口“拖出”到浮动窗口中。您可以创建停靠窗口,或将 MDI 内容移动到框架中,在需要时可以将其从 MDI 子窗体和浮动窗体之间重新父子化。 - Remy Lebeau