请教大富翁 ( 积分: 0 )

  • 主题发起人 主题发起人 小学生_hjz
  • 开始时间 开始时间

小学生_hjz

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Button2: TButton;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
procedure DoVisible;
procedure DoInvisible;
public
{ Public declarations }
end;

var
Form1: TForm1;
FullRgn, ClientRgn, CtlRgn : THandle;

implementation

{$R *.DFM}

procedure TForm1.DoInvisible;
var
AControl : TControl;
A, Margin, X, Y, CtlX, CtlY : Integer;
begin
Margin := ( Width - ClientWidth ) div 2;
FullRgn := CreateRectRgn(0, 0, Width, Height);
X := Margin;
Y := Height - ClientHeight - Margin;
ClientRgn := CreateRectRgn( X, Y, X + ClientWidth, Y + ClientHeight );
CombineRgn( FullRgn, FullRgn, ClientRgn, RGN_DIFF );
for A := 0 to1 ControlCount - 1 do begin
-----------------------------------------
AControl := Controls[A];
--------------------------------
if ( AControl is TWinControl ) or ( AControl is TGraphicControl )
-----------------------------------------------------------------------
then with AControl do begin
------------------------------------------
if [red]2[/red]Visible then begin
--------------------------------
CtlX := X + Left;
CtlY := Y + Top;
CtlRgn := CreateRectRgn( CtlX, CtlY, CtlX + Width, CtlY + Height );
CombineRgn( FullRgn, FullRgn, CtlRgn, RGN_OR );
end;
end;
end;
SetWindowRgn(Handle, FullRgn, TRUE);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
DeleteObject(ClientRgn);
DeleteObject(FullRgn);
DeleteObject(CtlRgn);
end;

procedure TForm1.DoVisible;
begin
FullRgn := CreateRectRgn(0, 0, Width, Height);
CombineRgn(FullRgn, FullRgn, FullRgn, RGN_COPY);
SetWindowRgn(Handle, FullRgn, TRUE);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
DoInvisible;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if Button1.Caption = 'Show' then begin
DoVisible;
Button1.Caption := 'Hide';
end
else begin
DoInvisible;
Button1.Caption := 'Show';
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
if Button1.Caption = 'Show' then
DoInvisible
else
DoVisible;
end;

end.
[black][/black]我是个初学者,以上是书上的范例,其中1,2处的字符范例中没定义,不太理解,还有就是带下划线的一段代码不知道是什么意思,希望大富翁能给解释一下谢谢!
 
后退
顶部