FMX Windows下无边框窗口处理

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;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值