Originally Posted by
wind_addict
I already know how to load the image using LoadImage, but this does not meet my requirements. I need to be able to load the bitmap into a memory DC, assign a HBITMAP handle to it so I can BitBlt it to my needs.
LoadImage() returns a HANDLE, which you can cast to a HBITMAP.
Create a compatible DC
SelectObject() the bitmap into the memory DC
Draw with BitBlt()
Clean up GDI
Call for a paint
** Note code written from memory so may not work..... **
Code:
//load image
HBITMAP hBMP = (HBITMAP*) LoadImage( hInst, "..\\Res\\SomeImage.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
//get a compatible DC
HDC hDC = GetDC( NULL);//whole screen
//get mem DC
HDC hMemDC = CreateCompatibleDC(hDC);
//select in our bitmap
hBITMAP hOrigBMP = (HBITMAP*) SelectObject(hMemDC, hBMP);
//use hMemDC to draw bitmap to screen DC (hDC)
//clean up
//put hMemDC back the way we created it
SelectObject(hMemDC, hOrigBMP);
//delete, release
ReleaseDC(hDC);
DeleteObject(hBMP);
DeleteObject(hMemDC);
//call for a paint
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);