有没有像窗口这样的东西被绘制到位图而不是显示表面



是否可以创建绘制在位图(充当虚拟显示表面)上而不是实际显示表面上的HWND?

这样的事情似乎很有用,因为你可以用一个窗口做一些DC无法做的事情,比如创建子窗口(可能包含控件)或通过GetDCEx获取DC。

我的问题的简单答案似乎是否定的!

您必须处理WM_PAINT并在那里绘制图像。

LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hDC, memDc;
    PAINTSTRUCT Ps;
    HBITMAP bmpBackground;
    BITMAP bm;
    switch (message)                   
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        case WM_PAINT:
            hDC = BeginPaint(hwnd, &Ps);
            // Load the bitmap from the resource
            bmpBackground = LoadBitmap(hInst, "your_background_image");
            // Create a memory device compatible with the above DC variable
            memDc = CreateCompatibleDC(hDC);
            // Select the new bitmap
            SelectObject(memDc, bmpBackground);
            GetObject(bmpBackground, sizeof(bm), &bm);
            // Copy the bits from the memory DC into the current dc
            BitBlt(hDC, 10, 10,bm.bmWidth, bm.bmHeight, memDc, 0, 0, SRCCOPY);
            // Restore the old bitmap
            DeleteDC(memDc);
            DeleteObject(bmpBackground);
            EndPaint(hwnd, &Ps);
            break;
        default:                    
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}

最新更新