views:

213

answers:

1

I'm trying to get thumbnail pictures of windows that are not visible.

Here's the code I have so far

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

For now, WindowProc is being called directly using FindWindow to get a handle, though, I eventually want to use EnumWindows to loop through all of the windows to get their thumbnails and store them in a linked list.

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

This code is in a DLL, which is called from a C# Forms application. For now the C# application just takes the bitmap and saves it to a file.

The problem is that unless I use "FindWindow" to get the visible window (which also happens to be the C# application), the picture ends up being a black box.

Is it possible to get an picture of a background window?

EDIT: This is a Windows Mobile application

A: 

There is no redrawing going on for invisible Windows, thats why you cannot get their content from the DC. Try sending a WM_PRINT message to the target window to request that it draws its content to your DC.

Edit:

Sorry, i did not notice this was for Windows Mobile. Other than WM_PRINT, i don't know a way to get the content of an invisible window. Of course you can still show the window (and make sure it is on top / not covered by other windows) and then run the code you have, but thats probably a bit messy.

freak
Thank you for responding. Unfortunatley, I neglected to mention I'm writing this for Windows Mobile, which apparently doesn't support the WM_PRINT message. Do you know if there is a Windows Mobile equivalent? I did some googling, but I couldn't find one.
zort15