Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. void HBITMAPfromHDC(HBITMAP &returnhbitmap, HDC hdcimage)
  2. {
  3. //prepare the returnhbitmap for get the size
  4. BITMAP structBitmapHeader;
  5. memset( &structBitmapHeader, 0, sizeof(BITMAP) );
  6. DeleteBitmap(returnhbitmap);
  7.  
  8. //get the hdc actual size
  9. returnhbitmap =(HBITMAP) GetCurrentObject(hdcimage, OBJ_BITMAP);
  10. GetObject(returnhbitmap, sizeof(BITMAP), &structBitmapHeader);
  11.  
  12. //create a hdc for select the returnhbitmap
  13. HDC hMemDC = CreateCompatibleDC(hdcimage);
  14.  
  15. //clean the returnhbitmap before create a new one
  16. DeleteBitmap(returnhbitmap);
  17. returnhbitmap = CreateCompatibleBitmap(hdcimage, structBitmapHeader.bmWidth,structBitmapHeader.bmHeight);
  18.  
  19. //select returnhbitmap to hMemDC
  20. HBITMAP hBmp2 = (HBITMAP)SelectObject(hMemDC, returnhbitmap);
  21.  
  22. //copy the hdcimage to hMemDC
  23. BitBlt(hMemDC,0,0,structBitmapHeader.bmWidth,structBitmapHeader.bmHeight,hdcimage,0,0,SRCCOPY);
  24.  
  25. //unselect the returnhbitmap for return it without problems
  26. SelectObject(hMemDC, hBmp2);
  27.  
  28. //and then delete the DC
  29. DeleteDC(hMemDC);
  30. }
  31.  
  32.  
  33.  
  34. //using:
  35. //hBmp it's my global HBITMAP member Menu
  36. //imgMenu give me the HDC
  37. HBITMAPfromHDC(hBmp,imgMenu);
  38. SetMenuItemBitmaps(MenuHandle,ID,MF_BYCOMMAND,(HBITMAP)hBmp ,(HBITMAP)hBmp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement