【发布时间】:2010-10-20 03:33:45
【问题描述】:
我正在尝试获取不可见窗口的缩略图。
这是我目前的代码
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 应用程序
【问题讨论】:
-
您是否尝试过在代码中调用 InvalidateRect() 来强制背景窗口重新绘制自身?
-
我尝试在获取窗口的 DC 之前和 BitBlt 之前调用 InvalidateRect。我也尝试过发送 WM_PAINT 消息,但这也没有成功。
标签: c++ windows-mobile gdi