Delphi中一个获得窗口图象的函数
2010-09-15 17:35
375 查看
过程名: CreateBMPFromWindow
功能: 获得一个句柄为Hwnd的窗口的图象
参数: Hwnd: 窗体句柄
PicBitNum: 图象位数(15,16,24,32)
返回值: TBitmap
function CreateBMPFromWindow(Hwnd: THandle;PicBitNum: Byte): TBitmap;
{创建一个空的Bitmap}
function CreateDibBMP(Dc: HDC;width,height: Integer): HBITMAP;
type
DibRec = record
bi: BITMAPINFOHEADER;
ct: array[0..255] of DWORD;
end;
var
Dib: DibRec;
lpBits: pointer;
temp: TBitmapInfo;
begin
dib.bi.biSize := sizeof(BITMAPINFOHEADER);
dib.bi.biWidth := width;
dib.bi.biHeight := height;
dib.bi.biBitCount := PicBitNum;
dib.bi.biPlanes := 1;
dib.bi.biCompression := 0;
dib.bi.biSizeImage := 0;
dib.bi.biClrUsed := 0;
if PicBitNum = 15 then
Dib.bi.biBitCount := 16
else if PicBitNum = 16 then
begin
Dib.bi.biCompression := BI_BITFIELDS;
dib.ct[0] := $F800;
dib.ct[1] := $07E0;
dib.ct[2] := $001F;
end;
Move(dib,temp,SizeOf(dib));
result := CreateDIBSection(Dc,temp,DIB_RGB_COLORS,lpBits,0,0);
end;
var
rc: TRect;
x,y,cx,cy: integer;
hdcScreen,hdcMemory: HDC;
begin
GetWindowRect(hwnd, rc);
x := rc.left;
y := rc.top;
cx := rc.right - rc.left;
cy := rc.bottom - rc.top;
hdcScreen := GetDC(0);
hdcMemory := CreateCompatibleDC(0);
result := TBitmap.Create;
Result.Handle := CreateDibBMP(hdcScreen, cx, cy);
SelectObject(hdcMemory, result.Handle);
BitBlt(hdcMemory, 0, 0, cx, cy, hdcScreen, x, y, SRCCOPY);
DeleteDC(hdcMemory);
ReleaseDC(0, hdcScreen);
end;
功能: 获得一个句柄为Hwnd的窗口的图象
参数: Hwnd: 窗体句柄
PicBitNum: 图象位数(15,16,24,32)
返回值: TBitmap
function CreateBMPFromWindow(Hwnd: THandle;PicBitNum: Byte): TBitmap;
{创建一个空的Bitmap}
function CreateDibBMP(Dc: HDC;width,height: Integer): HBITMAP;
type
DibRec = record
bi: BITMAPINFOHEADER;
ct: array[0..255] of DWORD;
end;
var
Dib: DibRec;
lpBits: pointer;
temp: TBitmapInfo;
begin
dib.bi.biSize := sizeof(BITMAPINFOHEADER);
dib.bi.biWidth := width;
dib.bi.biHeight := height;
dib.bi.biBitCount := PicBitNum;
dib.bi.biPlanes := 1;
dib.bi.biCompression := 0;
dib.bi.biSizeImage := 0;
dib.bi.biClrUsed := 0;
if PicBitNum = 15 then
Dib.bi.biBitCount := 16
else if PicBitNum = 16 then
begin
Dib.bi.biCompression := BI_BITFIELDS;
dib.ct[0] := $F800;
dib.ct[1] := $07E0;
dib.ct[2] := $001F;
end;
Move(dib,temp,SizeOf(dib));
result := CreateDIBSection(Dc,temp,DIB_RGB_COLORS,lpBits,0,0);
end;
var
rc: TRect;
x,y,cx,cy: integer;
hdcScreen,hdcMemory: HDC;
begin
GetWindowRect(hwnd, rc);
x := rc.left;
y := rc.top;
cx := rc.right - rc.left;
cy := rc.bottom - rc.top;
hdcScreen := GetDC(0);
hdcMemory := CreateCompatibleDC(0);
result := TBitmap.Create;
Result.Handle := CreateDibBMP(hdcScreen, cx, cy);
SelectObject(hdcMemory, result.Handle);
BitBlt(hdcMemory, 0, 0, cx, cy, hdcScreen, x, y, SRCCOPY);
DeleteDC(hdcMemory);
ReleaseDC(0, hdcScreen);
end;
相关文章推荐
- Delphi中一个获得窗口图象的函数
- 一个获得窗口图象的函数
- 在ASP.NET中一个弹出信息窗口及获得焦点的函数
- 用WindowFromPoint()函数来获得鼠标所在位置的窗口的句柄--发生一个关闭窗口的消息---关闭鼠标所在的窗口
- Delphi获得一个进程的主窗体(GetWindow(AHandle, GW_OWNER)等于0的窗体才是主窗体,并且要IsWindowVisible排除Application窗口)
- Delphi中的一个文件下载函数
- 在父窗口内有一iframe 无id,无name 怎么在父窗口内访问iframe内的一个函数
- 根据指定条件获得窗口的函数
- 改写了一个常用的DELPHI的加解密函数
- [Delphi] 计算目录大小的函数,获得目录文件列表,计算文件的大小
- 在用android日志的时候老是弹出一个窗口,内容为:"Copy" did not complete normally. Please see the log 和 什么函数,能达到和android手机上按“返回”键一样的效果?
- 设计一个数据结构,包含两个函数,1.插入一个数字,2.获得中数
- Delphi中的一个文件下载函数
- Sessions, Window Stations and Desktops(GetDesktopWindow函数得到的桌面句柄, 是Csrss.exe创建的一个窗口)
- Oracle函数 获得一个UUID
- 一个最简单的Delphi2010的PNG异形窗口方法
- 一个用delphi写的整合汇编与api的简单的窗口程序
- delphi的一个公用函数库
- 设计一个数据结构,其中包含两个函数,1.插入一个数字,2.获得中数。并估计时间复杂度。
- 怎样写一个获取数据函数:用TCP/IP通讯,向服务端发送命令,并从服务端获得返回数据.