PrintWindow 的问题!

wgqcsdn 2007-07-10 09:23:43
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 文件是一团黑。
...全文
646 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wgqcsdn 2007-07-19
  • 打赏
  • 举报
回复
还有个问题,因为 PrintWindow 只有 Win2003/XP 才支持,如何让我的程序在 Win2000 下正常运行?
wgqcsdn 2007-07-19
  • 打赏
  • 举报
回复
把 XP 下的 user32.dll 同时发布到2000系统的程序目录下,他还是会访问系统目录下的 user32.dll。这时把 user32.dll 改个名,程序引用改名后的 Dll,还是不行,提示无法定位另一个函数在 ntdll.dll 中,应该是在 PrintWindow 中引用了另一个 dll 中的函数。
怎么办呢?
wgqcsdn 2007-07-10
  • 打赏
  • 举报
回复
怎么调错了?
brightyang 2007-07-10
  • 打赏
  • 举报
回复
function PrintWindow(hWnd: HWND; hDCBlt: HWND; nFlags: Word): Bool; far; external 'user32.dll';
是否调错了
wgqcsdn 2007-07-10
  • 打赏
  • 举报
回复
用 Google、Baidu 查了,也查了以前的帖子,没有答案。
但是好像用其它语言没问题,怎么用 Delphi 就不行呢!
另外我的操作系统是 XP
wgqcsdn 2007-07-10
  • 打赏
  • 举报
回复
果然是这样!太感谢了!
不过为什么不能显示在 Image 中呢?
就是这句 ImgTum.Picture.Bitmap.Assign(lBmp); 为什么看不到效果呢?
constantine 2007-07-10
  • 打赏
  • 举报
回复
function PrintWindow(Wnd: HWND; hDCBlt: HDC; nFlags: DWord): Bool; stdcall external 'user32.dll';
改成这样就可以了,以前用过。
另外注意该函数95,98,win me 不支持
logne 2007-07-10
  • 打赏
  • 举报
回复
function PrintWindow(hWnd: HWND; hDCBlt: HWND; nFlags: Word): Bool; stdcall; external 'user32.dll';
改成这样试试
wgqcsdn 2007-07-10
  • 打赏
  • 举报
回复
我一次也没提前,还提示我提前的太频繁!气人!

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧