• Advertisement
Sign in to follow this  

[win32 GDI] Drawing a bitmap

This topic is 4041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

OK, mostly being a C++/DX programmer, my win 32 GDi skills are lacking and rusty. I am building a tool which I am using simple windows GDI stuff with, edit boxes, static controls etc. Nothing too fancy. Its a heightmap building tool and I'd like to be able to preview the bmp output as the tool runs. How do I display a bitmap in my window? I gather a bitmap is a STATIC control with SS_BITMAP style, and the handle of the bitmap in question. This makes the static control resize to the size of the bitmap, so we are getting somewhere. But how do I draw the bitmap? All the functions I've seen online involve catching the message WM_PAINT, and even I know that if you do that, nothing else will draw! So I need a way of updating the bitmap and presenting it. Please help! Thank you Simon

Share this post


Link to post
Share on other sites
Advertisement
using WM_PAINT is all very well, but as soon as I add

case WM_PAINT:
.....
break;



... to the code, all the other controls don't draw.

This I expected, since by specifying WM_PAINT you take responsibility for ALL painting from windows.

I just wanna have a bitmap which is updated. Not to have to manually draw every EDITBOX etc

Share this post


Link to post
Share on other sites
When you handle WM_PAINT you have to be sure to call BeginPaint, and EndPaint when you have finished. If you don't do this you will have unpredictable results, like you are seeing now.

By handling the WM_PAINT message you are not taking responsibility for painting ALL windows, just the window for which you are handling the message - you are responsible for doing it properly though ;)

Share this post


Link to post
Share on other sites
I agree, its only the single window which is affected by accepting WM_PAINT.

My problem is, this window has buttons and editboxes, as well as a bitmap. By using WM_PAINT to attempt to draw the bitmap, all the other buttons and editboxes are not painted!

from a tutorial:
    case WM_PAINT:
{
BITMAP bm;
PAINTSTRUCT ps;

HDC hdc = BeginPaint(hwnd, &ps);

HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = SelectObject(hdcMem, g_hbm);

GetObject(g_hbm, sizeof(bm), &bm);

BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);

EndPaint(hwnd, &ps);
}
break;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement