Pynolathgeen 19 Light Poster

Hello, I've got a pretty much burning question here.

Its about BitBlt. I have a window that functions as a button but I wanted to do some markup on it. So I the added BS_OWNERDRAW style to the button, and wanted to BitBlt an image on it. I tried it in WM_DRAWITEM first and it did not work. Then I tried it on WM_PAINT and it did work. I could not find anything on Google so maybe I can find more luck here.

This is the code:

HWND hwnd = Button;
BITMAP bm;
PAINTSTRUCT ps;				
LPDRAWITEMSTRUCT drawItem = (LPDRAWITEMSTRUCT)lParam;
HBITMAP g_hbmBall = (HBITMAP)LoadImage( NULL, "Test.bmp", IMAGE_BITMAP, 0, 0,
			       LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmBall);

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

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

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

EndPaint(hwnd, &ps);

There is no checking of variables here, but I did try it, they are all valid.
And I thought if it works in WM_PAINT, it should also work in WM_DRAWITEM.


Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.