PrintWindow()无法打印Google Chrome窗口(Chrome_WidgetWin_1) [英] PrintWindow() could not print Google Chrome window (Chrome_WidgetWin_1)

查看:720
本文介绍了PrintWindow()无法打印Google Chrome窗口(Chrome_WidgetWin_1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft Visual Studio 2010和Windows 7 Professional. 这是我的代码,用于将窗口图像复制到剪贴板:

I am using Microsoft Visual Studio 2010 and Windows 7 Professional. This is my code to copy window image to clipboard:

void PrintWindowEx( HWND hWnd )
{
    HDC hDCMem = CreateCompatibleDC(NULL);
    RECT rect;

    GetWindowRect(hWnd, &rect);

    HBITMAP hBmp = NULL;

    HDC hDC = GetDC(hWnd);

    hBmp = CreateCompatibleBitmap(hDC, rect.right - rect.left, rect.bottom - rect.top);

    HGDIOBJ hOld = SelectObject(hDCMem, hBmp);
    PrintWindow(hWnd, hDCMem, 0);

    SelectObject(hDCMem, hOld);
    DeleteObject(hDCMem);

    OpenClipboard(hWnd);

    EmptyClipboard(); 
    SetClipboardData(CF_BITMAP, hBmp);
    CloseClipboard();

    ReleaseDC(hWnd, hDC);
}

它在除Google Chrome浏览器主窗口之外的所有窗口中都可以正常工作.我以为是因为Chrome使用直接渲染,所以我在chrome://settings中禁用了硬件加速.仍然无法正常工作.然后,我意识到由于Chrome沙箱中的限制,可能会限制使用消息,因此我使用--no-sandbox命令行选项启动了Chrome.仍然不起作用.

It works fine with all windows except Google Chrome main window. I thought that it was because Chrome uses direct rendering, so I have disabled hardware acceleration in chrome://settings. Still does not work. Then I realized that working with messages can be limited due to restrictions in Chrome Sandbox, so I started Chrome with --no-sandbox command line option. Still does not work.

我该如何使用它?适用于Chrome和其他任何窗口(例如Chrome). BitBlt()是不可接受的,因为窗口的某些部分可能与另一个窗口重叠,该窗口可以位于其他桌面上,等等.有没有可行的解决方案?也许是通过DLL加载到另一个进程之类的.

How can I get this to work? For Chrome and any other windows like Chrome. BitBlt() is not acceptable because window some parts of the window may be overlapped by another windows, window can be on other desktop, etc. Is there any working solution? Maybe with DLL loading to another process or something like that.

UPD :它会在RedrawWindow()之后重绘;这样我就可以截屏了(某些部分-左侧部分(宽度〜20px)和右侧部分未复制).那么,它是否支持WM_PRINT?如何获取窗口的完整屏幕截图?

UPD: It does redraw after RedrawWindow(); so I can take screenshot (some parts - left part (width ~20px) and right part are not copied). So, does it support WM_PRINT or not? How can I take full screenshot of the window?

推荐答案

我对此坚持了很长时间,然后发现我可以将PW_RENDERFULLCONTENT作为最后一个参数传递给PrintWindow.谷歌搜索显示它是Windows 8.1中的新功能,因此大概无法在7上运行.尽管如此,还是值得尝试的,Winuser.h将其定义为

I was stuck for ages on this, then found that I can pass a parameter of PW_RENDERFULLCONTENT as the last parameter to PrintWindow. Googling that shows it's new in Windows 8.1 so presumably doesn't work on 7. It may be worth trying it though, Winuser.h defines it as

#if(_WIN32_WINNT >= 0x0603)
#define PW_RENDERFULLCONTENT    0x00000002
#endif /* _WIN32_WINNT >= 0x0603 */

这篇关于PrintWindow()无法打印Google Chrome窗口(Chrome_WidgetWin_1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆