1、窗口的Transparency不能为True
2、窗口BorderIcons设为[]
3、窗口BorderStyle设为Single
4、重定义WindowBorderStyle样式,把下面这段粘到StyleBook里
object TLayout
StyleName = 'windowborderstyle'
Align = Center
Size.Width = 800.000000000000000000
Size.Height = 600.000000000000000000
Size.PlatformDefault = False
TabOrder = 52
object TStyleObject
StyleName = 'mask'
Align = Contents
Locked = True
WrapMode = Tile
Visible = False
SourceLink = <
item
CapInsets.Left = 7.000000000000000000
CapInsets.Top = 7.000000000000000000
CapInsets.Right = 7.000000000000000000
CapInsets.Bottom = 7.000000000000000000
end>
end
object TActiveStyleObject
StyleName = 'left'
Align = MostLeft
Locked = True
Opacity = 0.000000000000000000
Position.Y = 1.000000000000000000
Size.Width = 1.000000000000000000
Size.Height = 599.000000000000000000
Size.PlatformDefault = False
ActiveTrigger = Active
ActiveLink = <
item
SourceRect.Left = 3.000000000000000000
SourceRect.Top = 2.000000000000000000
SourceRect.Right = 54.000000000000000000
SourceRect.Bottom = 10.000000000000000000
end>
SourceLink = <
item
SourceRect.Left = 2.000000000000000000
SourceRect.Top = 2.000000000000000000
SourceRect.Right = 54.000000000000000000
SourceRect.Bottom = 10.000000000000000000
end>
TouchAnimation.Link = <>
Opaque = True
end
object TActiveStyleObject
StyleName = 'right'
Align = MostRight
Locked = True
Opacity = 0.000000000000000000
Position.X = 799.000000000000000000
Position.Y = 1.000000000000000000
Size.Width = 1.000000000000000000
Size.Height = 599.000000000000000000
Size.PlatformDefault = False
ActiveTrigger = Active
ActiveLink = <
item
SourceRect.Left = 6.000000000000000000
SourceRect.Top = 3.000000000000000000
SourceRect.Right = 47.000000000000000000
SourceRect.Bottom = 10.000000000000000000
end>
SourceLink = <
item
end>
TouchAnimation.Link = <>
Opaque = True
end
object TActiveStyleObject
StyleName = 'bottom'
Align = Bottom
CapMode = Tile
Locked = True
Opacity = 0.000000000000000000
Position.X = 1.000000000000000000
Position.Y = 599.000000000000000000
Size.Width = 798.000000000000000000
Size.Height = 1.000000000000000000
Size.PlatformDefault = False
ActiveTrigger = Active
ActiveLink = <
item
SourceRect.Left = 3.000000000000000000
SourceRect.Top = 1.000000000000000000
SourceRect.Right = 46.000000000000000000
SourceRect.Bottom = 9.000000000000000000
end>
SourceLink = <
item
SourceRect.Left = 5.000000000000000000
SourceRect.Top = 1.000000000000000000
SourceRect.Right = 47.000000000000000000
SourceRect.Bottom = 8.000000000000000000
end>
TouchAnimation.Link = <>
Opaque = True
end
object TActiveStyleObject
Align = MostTop
Locked = True
Opacity = 0.000000000000000000
Size.Width = 800.000000000000000000
Size.Height = 1.000000000000000000
Size.PlatformDefault = False
ActiveTrigger = Active
ActiveLink = <
item
SourceRect.Left = 12.000000000000000000
SourceRect.Top = 2.000000000000000000
SourceRect.Right = 61.000000000000000000
SourceRect.Bottom = 10.000000000000000000
end>
SourceLink = <
item
SourceRect.Left = 5.000000000000000000
SourceRect.Top = 2.000000000000000000
SourceRect.Right = 45.000000000000000000
SourceRect.Bottom = 9.000000000000000000
end>
TouchAnimation.Link = <>
Opaque = True
end
object TLayout
StyleName = 'client'
Align = Client
Locked = True
HitTest = True
Size.Width = 798.000000000000000000
Size.Height = 598.000000000000000000
Size.PlatformDefault = False
end
end
5、在窗口里重载一个过程
// 窗口中声明部分
protected
procedure CreateHandle; override;
// 下面是实现部分
uses FMX.Platform.Win;
procedure TFrmMain.CreateHandle;
var
wnd: HWND;
oldStyle: NativeInt;
begin
inherited;
wnd := FormToHWND(Self);
if wnd <> 0 then
begin
oldStyle := Winapi.Windows.GetWindowLong(wnd, GWL_EXSTYLE);
Winapi.Windows.SetWindowLong(wnd, GWL_EXSTYLE, oldStyle or WS_EX_APPWINDOW or WS_MINIMIZEBOX);
oldStyle := Winapi.Windows.GetWindowLong(wnd, GWL_STYLE);
Winapi.Windows.SetWindowLong(wnd, GWL_STYLE, oldStyle or WS_MINIMIZEBOX or WS_MAXIMIZEBOX);
end;
end;
6、最小化按钮实现
procedure TFrmMain.btnMinimizeClick(Sender: TObject);
begin
Winapi.Windows.PostMessage(FormToHWND(Application.MainForm), WM_SYSCOMMAND, SC_MINIMIZE, 0);
end;
7、最大化\不愿按钮实现
procedure TFrmMain.btnMaxRestoreClick(Sender: TObject);
begin
if IsZoomed(FormToHWND(Self)) then
begin
Winapi.Windows.ShowWindow(FormToHWND(Application.MainForm), SW_SHOWNORMAL);
WindowState := TWindowState.wsNormal;
btnMaxRestore.StyleLookup := 'BtnMaximizeStyle';
end
else
begin
Winapi.Windows.ShowWindow(FormToHWND(Application.MainForm), SW_SHOWMAXIMIZED);
WindowState := TWindowState.wsMaximized;
btnMaxRestore.StyleLookup := 'BtnRestoreStyle';
end;
end;
8、自定义标题栏双击、拖动事件
procedure TFrmMain.backTopDblClick(Sender: TObject);
begin
btnMaxRestoreClick(nil);//双击时执行最大化\还原按钮事件
end;
procedure TFrmMain.backTopMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Single);
begin
// 最大化时不允许拖动
if WindowState = TWindowState.wsMaximized then
Exit;
// 鼠标左键按下时允许拖动
if ssLeft in Shift then
Self.StartWindowDrag;
end;