BitBlt 未在 Windows C++ API 中更新 WM_PAINT

BitBlt not updating WM_PAINT in Windows C++ API

我有以下函数可以将加载的位图绘制到 window。

void OnPaint(HWND hwnd) {
    PAINTSTRUCT     ps;
    HDC             hdc;
    BITMAP          bitmap;
    HDC             hdcMem;
    HGDIOBJ         oldBitmap;

    hdc = BeginPaint(hwnd, &ps);

    hdcMem = CreateCompatibleDC(hdc);
    HBITMAP bmp = mainBitmap;
    oldBitmap = SelectObject(hdcMem, mainBitmap);

    GetObject(bmp, sizeof(bitmap), &bitmap);

    x += 64;
    RECT rect;
    rect.left = x;
    rect.top = 0;
    rect.right = x+64;
    rect.bottom = 64;

    HBITMAP hBmp = CreateCompatibleBitmap(
        hdc,                    // Handle to a device context
        rect.right - rect.left, // Bitmap width
        rect.bottom - rect.top  // Bitmap height
    );

    BitBlt(
        hdc,                    // Destination rectangle context handle
        0,                      // Destination rectangle x-coordinate
        0,                      // Destination rectangle y-coordinate
        rect.right - rect.left, // Destination rectangle width
        rect.bottom - rect.top, // Destination rectangle height
        hdcMem,                 // A handle to the source device context
        rect.left,              // Source rectangle x-coordinate
        rect.top,               // Source rectangle y-coordinate
        SRCCOPY                 // Raster-operation code
    );

    SelectObject(hdcMem, oldBitmap);
    DeleteDC(hdcMem);

    EndPaint(hwnd, &ps);
}

并且我将以下图像加载到 HBITMAP mainBitmap 中:

图像在 window 打开成功时绘制,我在 sprite 位图中看到第一个图标(黄色抓钩),但我的问题是,当我按 'C' 到 re-paint window, sprite image 中的图片没有变化到下一个图标。

我知道的事情

为什么图形没有变化?


这是我的 WindowsProc 函数来处理 WM_PAINT 消息:

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    switch (uMsg) {
        HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

尝试调用 function InvalidateRect() 更新区域。