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

被折叠的 条评论
为什么被折叠?



