首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BitBlt未更新中的BitBlt WM_PAINT

BitBlt未更新中的BitBlt WM_PAINT
EN

Stack Overflow用户
提问于 2017-09-14 11:18:17
回答 1查看 1.2K关注 0票数 1

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

代码语言:javascript
复制
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

该图像是在窗口成功打开时绘制的,我在sprite位图中看到了第一个图标(黄色格斗钩子),但我的问题是,当我按'C'重新绘制窗口时,图像不会更改为雪碧图像中的下一个图标。

我知道的事情

  • 关于初始化,x = 64;
  • 每次我按'C'键,都会调用油漆。(在Visual调试器中确认)
  • 每次调用OnPaint时,x都会增加64。

为什么图形没有变化?

下面是我的WindowsProc函数,用于处理WM_PAINT消息:

代码语言:javascript
复制
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);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-14 11:35:17

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46217688

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档