獲取背景窗口的縮略圖 (Get Thumbnail of background window)


問題描述

獲取背景窗口的縮略圖 (Get Thumbnail of background window)

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

‑‑‑‑‑

參考解法

方法 1:

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.

(by zort15freak)

參考文件

  1. Get Thumbnail of background window (CC BY‑SA 3.0/4.0)

#gdi #windows-mobile #C++






相關問題

繪製鼠標光標 (Draw mouse cursor)

C 和 Windows GDI 中的雙緩衝 *framework* (Double-buffering *framework* in C and Windows GDI)

一個進程的 GDI 洩漏會影響其他進程嗎? (Can GDI leaks from one process affect other processes?)

BeginPath Textout EndPath 繪製反轉文本 (BeginPath Textout EndPath draws inverted text)

監控GDI通話 (Monitoring GDI calls)

如何捕獲(並希望修復)GDI 資源洩漏 (How to catch (and hopefully fix) a GDI resource leak)

如何使用 GDI(+) 在內存中渲染漸變 (How to render a gradient in memory using GDI(+))

使用 BITMAP::bmBits 與 GetDIBits 有什麼區別? (What is the difference between using BITMAP::bmBits vs GetDIBits?)

獲取背景窗口的縮略圖 (Get Thumbnail of background window)

AlphaBlend 返回“假”的原因可能是什麼 (What could be the reason for AlphaBlend to return 'false')

在 C++ 中查找像素 RGB 數據的最快方法是什麼? (What is the fastest method to lookup pixel RGB data in C++?)

逐行讀取文本框並將其視為單獨的文本 (Read a textbox line by line and treat it as a separate text)







留言討論