Delphi

КОМПЬЮТЕРНЫЕ КУРСЫ "ПОИСК"

[Главная страница] [Delphi] [Контакты]

Скрытие заголовка формы


Скырть заголовок формы

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    bShowCaption: TButton;
    bHideCaption: TButton;
    procedure bHideCaptionClick(Sender: TObject);
    procedure bShowCaptionClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure HideCaption;
    procedure ShowCaption;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.bHideCaptionClick(Sender: TObject);
begin
  HideCaption;
end;

procedure TForm1.bShowCaptionClick(Sender: TObject);
begin
  ShowCaption;
end;

procedure TForm1.HideCaption;
var
  OldStyle : Integer;
begin
  OldStyle := GetWindowLong(Handle, GWL_STYLE);
  if (OldStyle and WS_CAPTION) = WS_CAPTION then
  begin
    LockWindowUpdate(Handle);
    SetWindowLong(Handle, GWL_STYLE, OldStyle and not WS_CAPTION);
    Height := Height - getSystemMetrics(SM_CYCAPTION) - 2 * getSystemMetrics(SM_CYBORDER);
    Width := Width - 2 * getSystemMetrics(SM_CXBORDER);
    Top := Top + getSystemMetrics(SM_CYCAPTION) + getSystemMetrics(SM_CYBORDER);
    Left := Left + getSystemMetrics(SM_CXBORDER);
    LockWindowUpdate(0);
  end
end;

procedure TForm1.ShowCaption;
var
  OldStyle : Integer;
begin
  OldStyle := GetWindowLong(Handle, GWL_STYLE);
  if (OldStyle and WS_CAPTION) <> WS_CAPTION then
  begin
    LockWindowUpdate(Handle);
    SetWindowLong(Handle, GWL_STYLE, OldStyle or WS_CAPTION);
    Height := Height + GetSystemMetrics(SM_CYCAPTION) + 2 * GetSystemMetrics(SM_CYBORDER);
    Width := Width + 2 * GetSystemMetrics(SM_CXBORDER);
    Top := Top - getSystemMetrics(SM_CYCAPTION) - GetSystemMetrics(SM_CYBORDER);
    Left := Left - getSystemMetrics(SM_CXBORDER);
    LockWindowUpdate(0);
  end;
end;

end.

Исходный код здесь. Выполнен на Delphi XE.

Источник: codegearguru.com