delphi隐藏窗口标题栏

本文档介绍了如何使用Win32 API函数getWindowLong, getSystemMetrics和setWindowLong来实现对窗口标题栏的隐藏和显示。通过修改窗口风格,可以动态调整窗口的外观,适应不同的界面需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本实例主要使用为win32 API函数
getwindowLong:用于获取特定窗口的信息。
getSystemMatrics:用于获取系统规格及系统配置信息。
setWindowLong用于改变特定窗口的特性。

实现步骤:
添加两个button按钮,定义两个过程showTitleBar和HideTitleBar。代码如下:
在这里插入图片描述

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    btn1: TButton;
    btn2: TButton;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure HideTitleBar;
    procedure SHowTitleBar;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.HideTitleBar;
var
  Save:LongInt;
begin
  if BorderStyle=bsNone then Exit;
  Save:=GetWindowLong(Handle,GWL_STYLE);
  if (Save and ws_caption)=ws_caption then
  begin
    case BorderStyle of
      bsSingle,
      bsSizeable: SetWindowLong(handle,GWL_STYLE,Save and (not(WS_CAPTION))or WS_BORDER);
      bsDialog:SetWindowLong(Handle,GWL_STYLE,Save and (not(WS_CAPTION))or DS_MODALFRAME or WS_DLGFRAME);
    end;
    Height:=Height-getSystemMetrics(SM_CYCAPTION);
    Refresh;
  end;
end;

procedure TForm1.SHowTitleBar;
var
  save:LongInt;
begin
  if BorderStyle=bsNone then exit;
  save:=GetWindowLong(handle,GWL_STYLE);
  if(save and ws_caption)<>ws_caption then
  begin
    case BorderStyle of
      bsSingle,
      bsSizeable:SetWindowLong(Handle,GWL_STYLE,save or WS_CAPTION or WS_BORDER);
      bsDialog:SetWindowLong(Handle,GWL_STYLE,save or WS_CAPTION or DS_MODALFRAME or WS_DLGFRAME);
    end;
    Height:=Height+getSystemMetrics(SM_CYCAPTION);
    Refresh;
  end;
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
  HideTitleBar;
end;

procedure TForm1.btn2Click(Sender: TObject);
begin
  SHowTitleBar;
end;

end.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值