能帮我看一下这段代码吗?(关于异型窗口)(10分)

  • 主题发起人 主题发起人 jbas
  • 开始时间 开始时间
J

jbas

Unregistered / Unconfirmed
GUEST, unregistred user!

function Tform1.CreateRegion(wMask:TBitmap;wColor:TColor;hControl:THandle): HRGN;
var
dc, dc_c: HDC;
rgn: HRGN;
x, y: integer;
coord: TPoint;
line: boolean;
color: TColor;
begin
dc := GetWindowDC(hControl);
dc_c := CreateCompatibleDC(dc);
SelectObject(dc_c, wMask.Handle);
BeginPath(dc);
for x:=0 to wMask.Width-1 do
begin
line := false;
for y:=0 to wMask.Height-1 do
begin
color := GetPixel(dc_c, x, y);
if not (color = wColor) then
begin
if not line then
begin
line := true;
coord.x := x;
coord.y := y;
end;
end;
if (color = wColor) or (y=wMask.Height-1) then
begin
if line then
begin
line := false;
MoveToEx(dc, coord.x, coord.y, nil);
LineTo(dc, coord.x, y);
LineTo(dc, coord.x + 1, y);
LineTo(dc, coord.x + 1, coord.y);
CloseFigure(dc);
end;
end;
end;
end;
EndPath(dc);
rgn := PathToRegion(dc);
ReleaseDC(hControl, dc);
Result := rgn;
end;


procedure TForm1.FormCreate(Sender: TObject);
var
w1:TBitmap;
w2:TColor;
rgn: HRGN;
begin
w1:=TBitmap.Create;
w1.Assign(image1.Picture.Bitmap);
w2:=w1.Canvas.Pixels[0,0];
rgn := CreateRegion(w1,w2,Handle);
if rgn<>0 then
begin
SetWindowRgn(Handle, rgn, true);
end;
w1.Free;
end;
不好意思。只有这点分了!!!能帮我吗,大侠码?
 
粗看了一下,你要问什么?
 
YB_unique谢谢关注!!!
关于GetWindowDC,CreateCompatibleDC,SelectObject,BeginPath。。在CreateRegion中
作用。我对它们点不懂,谢谢了!!!
 
GetWindowDC:
>>Get the DC Handle of the Window.
CreateCompatibleDC:
>>Create a Compatible DC.
SelectObject:
>>Select a Object.
BeginPath:
>>Begin to Get the Path of the DC;
EndPath:
>>End to Get the Path.
To Create a RgnWindow is very easy:
var
dc:HDC;
rgn :HRGN;
begin
dc := self.canvas.handle;
BeginPath(dc);
self.canvas.font.size := 20;
self.canvas.font.color := clBlack;
self.canvas.textout(20,20,'X');
EndPath(dc);
rgn := PathToRegion(dc);
SetWindowRgn(self.Hadle,rgn,true);
end;
Now you can see a "X" form;
 
不行。请指教!!!

procedure TForm1.Button1Click(Sender: TObject);
var
dc:HDC;
rgn :HRGN;
begin
dc:= self.canvas.handle;
BeginPath(dc);
self.canvas.font.size := 20;
self.canvas.font.color := clBlack;
self.canvas.textout(20,20,'X');
EndPath(dc);
rgn := PathToRegion(dc);
SetWindowRgn(self.Handle,rgn,true);
end;
 
varphone,YB_unique大侠,能否帮我一把!!!
 
Put the code in the Form.Create(...) event!
try again!
 
好象还是不行,不知为什么?能否再帮一下忙!!!
 
Okay,like this:
procedure TForm1.Button1Click(Sender: TObject);
var
dc:HDC;
rgn :HRGN;
begin
dc:= self.canvas.handle;
with self.canvas do begin
font.color := clblack;
font.size := 200;
font.name := 'Tahoma';
brush.style := bsclear;
end;
BeginPath(dc);
self.canvas.textout(20,20,'X');
EndPath(dc);
rgn := PathToRegion(dc);
self.color := clteal;
SetWindowRgn(self.Handle,rgn,true);
end;
have a try,please!
 
http://www.ocloud.com/article/viewart.php?id=191
 
谢谢《varphone》及大家的关注。其余用图象来构成窗口我自己慢慢研究吧,毕竟分太少了
不过要是还有大侠来帮我,那太好了!!!
 
后退
顶部