Chinaunix首页 | 论坛 | 博客
  • 博客访问: 16496762
  • 博文数量: 5645
  • 博客积分: 9880
  • 博客等级: 中将
  • 技术积分: 68081
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-28 13:35
文章分类

全部博文(5645)

文章存档

2008年(5645)

我的朋友

分类:

2008-04-28 20:52:13

下载本文示例代码
p>  我不知道全透明的窗口有什么用,但毕竟作为一种技巧,还是拿出来说说吧。下面这个例子演示如何显示透明的窗口.同时也介绍了如何捕获屏幕.必须把Form1的BorderStyle属性置为bsNone      C Builder   请参照Delphi的例子   Delphi unit homepage_coolform;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs ExtCtrls, StdCtrls, Buttons; type TForm1 = class(TForm) procedure FormPaint(Sender: TObject); procedure FormShow(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } hbmp:integer; end; var Form1: TForm1; implementation {$R *.DFM} function CopyScreenToBitmap(Rect:TREct):integer; var hScrDC, hMemDC, hBitmap, hOldBitmap:integer; nX, nY, nX2, nY2: integer; nWidth, nHeight:integer; xScrn, yScrn:integer; begin if (IsRectEmpty(Rect)) then begin result:= 0; exit; end; // 获得屏幕缓冲区的句柄. // a memory DC compatible to screen DC hScrDC:= CreateDC(DISPLAY, pchar(0), pchar(0), PDeviceModeA(0)); hMemDC:= CreateCompatibleDC(hScrDC); // get points of rectangle to grab nX := rect.left; nY := rect.top; nX2 := rect.right; nY2 := rect.bottom; // get screen resolution xScrn:= GetDeviceCaps(hScrDC, HORZRES); yScrn := GetDeviceCaps(hScrDC, VERTRES); //make sure bitmap rectangle is visible if (nX $#@60;0) then nX :="0;" if (nY $#@60; 0) then nY :="0;" if (nX2$#@62; xScrn) then nX2 := xScrn; if (nY2 $#@62; yScrn) then nY2 := yScrn; nWidth := nX2 - nX; n ght := nY2 - nY; // create a bitmap compatible with the screen DC hBitmap := CreateCompatibleBitmap(hScrDC, nWidth, nHeight); // select new bitmap into memory DC hOldBitmap := SelectObject(hMemDC, hBitmap); // bitblt screen DC to memory DC BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY); // select old bitmap back into memory DC and get handle to // bitmap of the screen hBitmap := SelectObject(hMemDC, hOldBitmap); // clean up DeleteDC(hScrDC); DeleteDC(hMemDC); result:= hBitmap; end; procedure TForm1.FormShow(Sender: TObject); Var rect:TRect; p:TPoint; begin rect:=ClientRect; p:=ClientOrigin; rect.left:=p.x; rect.top:=p.y; rect.bottom:=rect.bottom p.y; rect.right:=rect.right p.x; hbmp:=copyScreenToBitmap(rect); inherited; end; procedure TForm1.FormPaint(Sender: TObject); var bitmap:TBitmap; rect:TRect; begin bitmap:=TBitmap.create; bitmap.handle:=hbmp; rect:=ClientRect; canvas.draw(rect.left,rect.top,bitmap); bitmap.handle:=0; bitmap.free; end; procedure TForm1.FormDestroy(Sender: TObject); begin DeleteObject(hbmp); end; end. p>  我不知道全透明的窗口有什么用,但毕竟作为一种技巧,还是拿出来说说吧。下面这个例子演示如何显示透明的窗口.同时也介绍了如何捕获屏幕.必须把Form1的BorderStyle属性置为bsNone      C Builder   请参照Delphi的例子   Delphi unit homepage_coolform;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs ExtCtrls, StdCtrls, Buttons; type TForm1 = class(TForm) procedure FormPaint(Sender: TObject); procedure FormShow(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } hbmp:integer; end; var Form1: TForm1; implementation {$R *.DFM} function CopyScreenToBitmap(Rect:TREct):integer; var hScrDC, hMemDC, hBitmap, hOldBitmap:integer; nX, nY, nX2, nY2: integer; nWidth, nHeight:integer; xScrn, yScrn:integer; begin if (IsRectEmpty(Rect)) then begin result:= 0; exit; end; // 获得屏幕缓冲区的句柄. // a memory DC compatible to screen DC hScrDC:= CreateDC(DISPLAY, pchar(0), pchar(0), PDeviceModeA(0)); hMemDC:= CreateCompatibleDC(hScrDC); // get points of rectangle to grab nX := rect.left; nY := rect.top; nX2 := rect.right; nY2 := rect.bottom; // get screen resolution xScrn:= GetDeviceCaps(hScrDC, HORZRES); yScrn := GetDeviceCaps(hScrDC, VERTRES); //make sure bitmap rectangle is visible if (nX $#@60;0) then nX :="0;" if (nY $#@60; 0) then nY :="0;" if (nX2$#@62; xScrn) then nX2 := xScrn; if (nY2 $#@62; yScrn) then nY2 := yScrn; nWidth := nX2 - nX; n ght := nY2 - nY; // create a bitmap compatible with the screen DC hBitmap := CreateCompatibleBitmap(hScrDC, nWidth, nHeight); // select new bitmap into memory DC hOldBitmap := SelectObject(hMemDC, hBitmap); // bitblt screen DC to memory DC BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY); // select old bitmap back into memory DC and get handle to // bitmap of the screen hBitmap := SelectObject(hMemDC, hOldBitmap); // clean up DeleteDC(hScrDC); DeleteDC(hMemDC); result:= hBitmap; end; procedure TForm1.FormShow(Sender: TObject); Var rect:TRect; p:TPoint; begin rect:=ClientRect; p:=ClientOrigin; rect.left:=p.x; rect.top:=p.y; rect.bottom:=rect.bottom p.y; rect.right:=rect.right p.x; hbmp:=copyScreenToBitmap(rect); inherited; end; procedure TForm1.FormPaint(Sender: TObject); var bitmap:TBitmap; rect:TRect; begin bitmap:=TBitmap.create; bitmap.handle:=hbmp; rect:=ClientRect; canvas.draw(rect.left,rect.top,bitmap); bitmap.handle:=0; bitmap.free; end; procedure TForm1.FormDestroy(Sender: TObject); begin DeleteObject(hbmp); end; end. 下载本文示例代码


怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口怎样制作全透明的窗口
阅读(137) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~