K
kingone
Unregistered / Unconfirmed
GUEST, unregistred user!
因为PrintWindow函数在XP下可以用来进行特殊截图,比如一个窗口即使被另一窗口所遮挡,也能被完全截出图来,所以引出了下面的问题,还请朋友们相助:
这是C#中一段代码,执行后可以正确对"计算器"界面进行截图
只要窗体的visable为true,即使它在屏幕的外面也可以抓到图。如果为false,就是一张黑图了,赫赫。
public static Bitmap GetWindow(IntPtr hWnd)
{
IntPtr hscrdc = GetWindowDC(hWnd);
Control control = Control.FromHandle(hWnd);
IntPtr hbitmap = CreateCompatibleBitmap(hscrdc, control.Width, control.Height);
IntPtr hmemdc = CreateCompatibleDC(hscrdc);
SelectObject(hmemdc, hbitmap);
PrintWindow(hWnd, hmemdc, 0);
Bitmap bmp = Bitmap.FromHbitmap(hbitmap);
DeleteDC(hscrdc);//删除用过的对象
DeleteDC(hmemdc);//删除用过的对象
return bmp;
}
--------------------------------
[blue]我的问题,我将其转化成DELPHI代码后,对计算机截图为何只是一片空白[/blue]:
...
function PrintWindow(hwnd:HWND;hdcBlt:HWND;nFlags:word ):boolean;far;external 'user32.dll';
...
procedure TForm1.Button3Click(Sender: TObject);
var
Wind_hwnd,hscrdc, hbitmap, hmemdc: Integer;
Rect: TRect;
begin
Wind_hwnd := FindWindow('SciCalc', '计算器');
hscrdc := GetWindowDC(Wind_hwnd);
GetWindowRect(Wind_hwnd, Rect);
hbitmap := CreateCompatibleBitmap(hscrdc, Rect.Right-Rect.Left, Rect.Bottom-Rect.Top);
hmemdc := CreateCompatibleDC(hscrdc);
SelectObject(hmemdc, hbitmap);
PrintWindow(Wind_hwnd, hmemdc, 0);
Image1.Picture.Bitmap := TBitMap.Create;
Image1.Picture.Bitmap.Handle := hbitmap;
Image1.Picture.Bitmap.Canvas.Refresh;
DeleteDC(hscrdc);//删除用过的对象
DeleteDC(hmemdc);//删除用过的对象
DeleteObject(hbitmap);
end;
这是C#中一段代码,执行后可以正确对"计算器"界面进行截图
只要窗体的visable为true,即使它在屏幕的外面也可以抓到图。如果为false,就是一张黑图了,赫赫。
public static Bitmap GetWindow(IntPtr hWnd)
{
IntPtr hscrdc = GetWindowDC(hWnd);
Control control = Control.FromHandle(hWnd);
IntPtr hbitmap = CreateCompatibleBitmap(hscrdc, control.Width, control.Height);
IntPtr hmemdc = CreateCompatibleDC(hscrdc);
SelectObject(hmemdc, hbitmap);
PrintWindow(hWnd, hmemdc, 0);
Bitmap bmp = Bitmap.FromHbitmap(hbitmap);
DeleteDC(hscrdc);//删除用过的对象
DeleteDC(hmemdc);//删除用过的对象
return bmp;
}
--------------------------------
[blue]我的问题,我将其转化成DELPHI代码后,对计算机截图为何只是一片空白[/blue]:
...
function PrintWindow(hwnd:HWND;hdcBlt:HWND;nFlags:word ):boolean;far;external 'user32.dll';
...
procedure TForm1.Button3Click(Sender: TObject);
var
Wind_hwnd,hscrdc, hbitmap, hmemdc: Integer;
Rect: TRect;
begin
Wind_hwnd := FindWindow('SciCalc', '计算器');
hscrdc := GetWindowDC(Wind_hwnd);
GetWindowRect(Wind_hwnd, Rect);
hbitmap := CreateCompatibleBitmap(hscrdc, Rect.Right-Rect.Left, Rect.Bottom-Rect.Top);
hmemdc := CreateCompatibleDC(hscrdc);
SelectObject(hmemdc, hbitmap);
PrintWindow(Wind_hwnd, hmemdc, 0);
Image1.Picture.Bitmap := TBitMap.Create;
Image1.Picture.Bitmap.Handle := hbitmap;
Image1.Picture.Bitmap.Canvas.Refresh;
DeleteDC(hscrdc);//删除用过的对象
DeleteDC(hmemdc);//删除用过的对象
DeleteObject(hbitmap);
end;