Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void HBITMAPfromHDC(HBITMAP &returnhbitmap, HDC hdcimage)
- {
- //prepare the returnhbitmap for get the size
- BITMAP structBitmapHeader;
- memset( &structBitmapHeader, 0, sizeof(BITMAP) );
- DeleteBitmap(returnhbitmap);
- //get the hdc actual size
- returnhbitmap =(HBITMAP) GetCurrentObject(hdcimage, OBJ_BITMAP);
- GetObject(returnhbitmap, sizeof(BITMAP), &structBitmapHeader);
- //create a hdc for select the returnhbitmap
- HDC hMemDC = CreateCompatibleDC(hdcimage);
- //clean the returnhbitmap before create a new one
- DeleteBitmap(returnhbitmap);
- returnhbitmap = CreateCompatibleBitmap(hdcimage, structBitmapHeader.bmWidth,structBitmapHeader.bmHeight);
- //select returnhbitmap to hMemDC
- HBITMAP hBmp2 = (HBITMAP)SelectObject(hMemDC, returnhbitmap);
- //copy the hdcimage to hMemDC
- BitBlt(hMemDC,0,0,structBitmapHeader.bmWidth,structBitmapHeader.bmHeight,hdcimage,0,0,SRCCOPY);
- //unselect the returnhbitmap for return it without problems
- SelectObject(hMemDC, hBmp2);
- //and then delete the DC
- DeleteDC(hMemDC);
- }
- //using:
- //hBmp it's my global HBITMAP member Menu
- //imgMenu give me the HDC
- HBITMAPfromHDC(hBmp,imgMenu);
- SetMenuItemBitmaps(MenuHandle,ID,MF_BYCOMMAND,(HBITMAP)hBmp ,(HBITMAP)hBmp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement