PrintWindow 的问题!
function PrintWindow(hWnd: HWND; hDCBlt: HWND; nFlags: Word): Bool; far; external 'user32.dll';
procedure TMainform.Button2Click(Sender: TObject);
var
lHwnd: HWND;
lhDC, lhBmp, lhMemDC: Integer;
lRect: TRect;
lBmp: TBitmap;
begin
if lvCurWin.Selected = nil then Exit;
lHwnd := StrToInt(lvCurWin.Selected.SubItems[0]);
{ 用了一个 ListView 保存当前窗口的句柄 }
lhDC := GetWindowDC(lHwnd);
if lhDC <> 0 then
begin
lhMemDC := CreateCompatibleDC(lhDC);
if lhMemDC <> 0 then
begin
GetWindowRect(lHwnd, lRect);
lhBmp := CreateCompatibleBitmap(lhDC, lRect.Right-lRect.Left, lRect.Bottom-lRect.Top);
if lhBmp <> 0 then
begin
SelectObject(lhMemDC, lhBmp);
if not PrintWindow(lHwnd, lhMemDC, 0) then
ShowMessage('不成功!'); { 老是提示不成功 }
lBmp := TBitmap.Create;
lBmp.Handle := lhBmp;
lBmp.SaveToFile('c:\abc.bmp');
ImgTum.Picture.Bitmap.Assign(lBmp);
lBmp.Free;
DeleteObject(lhBmp);
end;
DeleteObject(lhMemDC);
end;
ReleaseDC(lHwnd, lhDC);
end;
end;
上面代码,为什么执行 PrintWindow 时老是提示不成功呢!保存的 Bmp 文件是一团黑。