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);
此代码位于DLL中,该DLL从C#Forms应用程序调用。目前,C#应用程序只是获取位图并将其保存到文件中。
问题是,除非我使用FindWindow
来获得可见窗口(这也恰好是C#应用程序),图片最终成为一个黑盒子。
是否有可能获得背景窗口的图片?
编辑:这是Windows Mobile应用程序
您是否试过在代码中调用InvalidateRect()来强制背景窗口重新绘制自己? – Kluge 2009-04-17 16:52:02
我已经尝试在获取窗口DC之前以及BitBlt之前调用InvalidateRect。我也尝试发送一条WM_PAINT消息,但这也没有办法。 – zort15 2009-04-20 16:36:55