随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

本例效果图:



代码文件:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    procedure CheckBox1Click(Sender: TObject);
  private
    procedure MyMsg(var Msg: TWMNCHitTest); message WM_NCHITTEST;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) xor WS_CAPTION);
  if not CheckBox1.Checked then begin Hide; Show; end;
end;

procedure TForm1.MyMsg(var Msg: TWMNCHitTest);
begin
  Inherited;
  if Msg.Result = HTCLIENT then Msg.Result := HTCAPTION;
end;

end.

窗体文件:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 107
  ClientWidth = 228
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object CheckBox1: TCheckBox
    Left = 32
    Top = 40
    Width = 161
    Height = 17
    Caption = #26080#26631#39064#26639#20294#26377#36793#26694#30340#31383#21475
    TabOrder = 0
    OnClick = CheckBox1Click
  end
end

posted on 2008-08-29 14:45  万一  阅读(...)  评论(...编辑  收藏