您的位置:首页 > 编程语言 > Delphi

Delphi实现透明窗体

2009-12-01 10:30 218 查看
unit unitMain;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure WMGetMinMaxInfo(var msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
FullRgn, ClientRgn, ButtonRgn: THandle;
Margin, X, Y: 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);
X := X + Button1.Left;
Y := Y + Button1.Top;
ButtonRgn := CreateRectRgn(X, Y, X + Button1.Width, Y + Button1.Height);
CombineRgn(FullRgn, FullRgn, ButtonRgn, RGN_OR);
SetWindowRgn(Handle, FullRgn, True);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
lf : TLogFont;
tf : TFont;
begin
with Form1.Canvas do
begin
Font.Name := 'Arial';
Font.Size := 24;
tf := TFont.Create;
try
tf.Assign(Font) ;
GetObject(tf.Handle, sizeof(lf), @lf) ;
lf.lfEscapement := 450;
lf.lfOrientation := 450;
tf.Handle := CreateFontIndirect(lf) ;
Font.Assign(tf) ;
finally
tf.Free;
end;
TextOut(20, Height div 2, 'Rotated Text!') ;
end;
end;

procedure TForm1.WMGetMinMaxInfo(var msg: TWMGetMinMaxInfo);
begin
inherited;
with msg.MinMaxInfo^.ptMaxTrackSize do
begin
X := GetDeviceCaps(Canvas.Handle, HORZRES) + (Width - ClientWidth) ;
Y := GetDeviceCaps(Canvas.Handle, VERTRES) + (Height - ClientHeight) ;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
Const
{$J+}
Rect: TRect = (Left:0; Top:0; Right:0; Bottom:0);
{$J-}
begin
if Left > 0 then
begin
Rect := BoundsRect;
SetBounds(
Left - ClientOrigin.X,
Top - ClientOrigin.Y,
GetDeviceCaps(Canvas.Handle, HORZRES) + (Width - ClientWidth),
GetDeviceCaps(Canvas.Handle, VERTRES) + (Height - ClientHeight)
);
end
else BoundsRect := Rect;
end;

{$J+}
procedure TForm1.Button3Click(Sender: TObject);
const
i: integer = 0;
begin
ShowMessage(IntToStr(i));
Inc(i);
ShowMessage(IntToStr(i));
end;

end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: