如何实现不规则窗口?(200分)

  • 主题发起人 主题发起人 tr
  • 开始时间 开始时间
相关问题太多了。
用SetWindowRgn这个API
 
先用CreatePolygonRgn之类的函数建立轮廓
 
先用
CreateEllipticRgn
CreateEllipticRgnIndirect
CreatePolygonRgn
CreatePolyPolygonRgn
CreateRectRgn
再用SetWindowRgn
 
不规则窗口的实现,用下面的程序
unit s1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure FormMouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
procedure FormPaint(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
const
MyRgn : Array[1..8] of integer =(2,135,115,22,228,135,2,135);
//区域坐标
var
mx,my: integer;
HR: HRGN;
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin

Form1.Color := clblack;
Form1.Canvas.Font.Size:=12;
Form1.Canvas.Font.Style:=Form1.Canvas.Font.Style + [fsBold];
Form1.Canvas.Font.Color := clred;
HR:=CreatePolygonRgn(MyRgn,4,ALTERNATE);
//创建一个区域
SetWindowRgn(Form1.Handle,HR,False);
// 设置窗口区域
UpdateWindow(Form1.Handle);
//更新窗口
end;

procedure TForm1.FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin

mx:=x;
my:=y;
end;

procedure TForm1.FormMouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
begin

if ssLeft in shift then

begin

Form1.Left := Form1.Left - mx+x;
Form1.Top := Form1.Top - My +y;
end;

end;

procedure TForm1.FormPaint(Sender: TObject);
begin

Form1.Canvas.TextOut(50,60,'Alt+F4 to Quit');
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin

DeleteObject(HR);
//删除区域
end;

end.
 
//以下代码抄自Delphi高级开发指南
//建立一个半圆形的窗口。
procedure TForm1.FormCreate(Sender:TObject);
var
hRegion:Thandle;
begin
hRegion:=CreateEllipticRgn(0,-Height,Width,Height);
SetWindowRgn(Handle,hRegion,True);
end;

 
接受答案了.
 
后退
顶部