获取背景窗口的缩略图

时间:2009-04-17 16:02:30

标签: c++ windows-mobile gdi

我正在尝试获取不可见的窗口的缩略图。

这是我到目前为止的代码

BOOL CALLBACK WindowProc(HWND hWnd, LPARAM lParam)
{
    RECT WindRect;
    GetWindowRect(hWnd, &WindRect)
    CurrentScreenShot->Next = new ScreenShotList();
    CurrentScreenShot = CurrentScreenShot->Next;

    HDC SourceDC = GetDC(hWnd);
    HDC TargetDC = CreateCompatibleDC(SourceDC);
    CurrentScreenShot->ScreenShot = CreateCompatibleBitmap(SourceDC, WindRect.right - WindRect.left, WindRect.bottom - WindRect.top);

    BitBlt(TargetDC, 0, 0, WindRect.right - WindRect.left, WindRect.bottom - WindRect.top, SourceDC, 0, 0, SRCCOPY);

    ReleaseDC(hWnd, SourceDC);

    g_iWindows++;
    return TRUE;
}

目前,正在使用WindowProc直接调用FindWindow来获取句柄,但我最终希望使用EnumWindows遍历所有窗口以获取缩略图和将它们存储在链表中。

WindowProc(FindWindow(NULL, L"File Explorer"), 0);

此代码位于DLL中,该DLL是从C#Forms应用程序调用的。现在,C#应用程序只获取位图并将其保存到文件中。

问题在于,除非我使用FindWindow来获取可见窗口(也恰好是C#应用程序),否则图片最终会成为黑盒子。

是否可以获得背景窗口的图片?

编辑:这是Windows Mobile应用程序

1 个答案:

答案 0 :(得分:0)

对于隐形Windows没有重新绘制,这就是为什么你无法从DC获取其内容的原因。尝试向目标窗口发送WM_PRINT消息,请求将其内容提取到DC。

修改

抱歉,我没有注意到这是针对Windows Mobile的。除了WM_PRINT之外,我不知道如何获取不可见窗口的内容。当然,您仍然可以显示窗口(并确保它位于顶部/未被其他窗口覆盖),然后运行您拥有的代码,但这可能有点混乱。