I have a window using Win32 and in the message handler I have a case for WM_PAINT, so that a bitmap is drawn in the window. However on running the bitmap is not drawn, is there something I am missing? Do I need to manually send the WM_PAINT message?
Here is the code I have: http://pastebin.com/bi48LB0U
and this is the WM_PAINT case:
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;
Your bitmap doesn't show, because your call to
LoadBitmap
returnsNULL
, due to an invalid lpBitmapName argument. From the documentation for LoadBitmap:In other words:
LoadBitmap
can only load bitmaps from Resources of type RT_BITMAP (or predefined bitmaps provided by the system). If you need to load a bitmap from disk, use LoadImage instead.If you need to load image data other than plain bitmap files, consider using the Windows Imaging Component.