在 XP 中从隐藏或剪切的窗口复制内容? [英] Copying content from a hidden or clipped window in XP?
问题描述
我需要将隐藏的窗口 (BitBlt) 的内容复制到另一个窗口.问题是一旦我隐藏了源窗口,我得到的设备上下文就不再绘制了.
I need to copy the content of a window (BitBlt) which is hidden, to another window. The problem is that once I hide the source window, the device context I got isn't painted anymore.
推荐答案
您需要的是 PrintWindow 函数.如果您需要它与旧版本的 Windows 一起使用,您可以尝试 WM_PRINT,虽然我一直无法让它发挥作用.
What you need is the PrintWindow function that's available in Win32 API since Windows XP. If you need it to work with older versions of Windows, you can try WM_PRINT, although I've never been able to make it work.
有一篇很好的文章这里 展示了如何使用 PrintWindow,这是该文章中的相关代码片段:
There's a nice article here that shows how to use PrintWindow, and here's the relevant code snippet from that article:
// Takes a snapshot of the window hwnd, stored in the memory device context hdcMem
HDC hdc = GetWindowDC(hwnd);
if (hdc)
{
HDC hdcMem = CreateCompatibleDC(hdc);
if (hdcMem)
{
RECT rc;
GetWindowRect(hwnd, &rc);
HBITMAP hbitmap = CreateCompatibleBitmap(hdc, RECTWIDTH(rc), RECTHEIGHT(rc));
if (hbitmap)
{
SelectObject(hdcMem, hbitmap);
PrintWindow(hwnd, hdcMem, 0);
DeleteObject(hbitmap);
}
DeleteObject(hdcMem);
}
ReleaseDC(hwnd, hdc);
}
我应该有一些使用 wxPython 来实现相同功能的 Python 代码.如果需要,请给我留言.
I should have some Python code that uses wxPython to achieve the same thing. Drop me a note if you want it.
这篇关于在 XP 中从隐藏或剪切的窗口复制内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!