2

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

这是我到目前为止的代码

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);

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

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

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

编辑:这是一个 Windows Mobile 应用程序

4

1 回答 1

0

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

编辑:

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

于 2009-04-18T13:33:40.467 回答