未在 Win32 C++ 中绘制位图

Bitmap not being painted in Win32 C++

我有一个使用 Win32 的 window,在消息处理程序中我有一个 WM_PAINT 的案例,因此在 window 中绘制了一个位图。但是在 运行 上没有绘制位图,是不是我遗漏了什么?我需要手动发送 WM_PAINT 消息吗?

这是我的代码:http://pastebin.com/bi48LB0U

这是 WM_PAINT 案例:

case WM_PAINT:
    hDC = BeginPaint(hwnd, &ps);
    bmp = LoadBitmap(hInst, L"C:\example.bmp");
    memDCExercising = CreateCompatibleDC(hDC);
    SelectObject(memDCExercising, bmp);
    BitBlt(hDC, 100, 100, 500, 500, memDCExercising, 0, 0, SRCCOPY);
    DeleteDC(memDCExercising);
    DeleteObject(bmp);
    EndPaint(hwnd, &ps);
    break;

您的位图没有显示,因为您调用 LoadBitmap returns NULL,由于 lpBitmapName 参数无效。来自 LoadBitmap 的文档:

lpBitmapName [in]: A pointer to a null-terminated string that contains the name of the bitmap resource to be loaded. Alternatively, this parameter can consist of the resource identifier in the low-order word and zero in the high-order word. The MAKEINTRESOURCE macro can be used to create this value.

换句话说:LoadBitmap 只能从 Resources of type RT_BITMAP (or predefined bitmaps provided by the system). If you need to load a bitmap from disk, use LoadImage 加载位图。

如果您需要加载普通位图文件以外的图像数据,请考虑使用 Windows Imaging Component