How to convert HICON to HBITMAP in VC++?

后端 未结 4 1781
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-10 19:18

How to convert HICON to HBITMAP in VC++?

I know this is an FAQ but all the solutions I\'ve found on Google don\'t work. What I need is a function which takes a param

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 19:30

    HDC hDC = GetDC(NULL);
    HDC hMemDC = CreateCompatibleDC(hDC);
    HBITMAP hMemBmp = CreateCompatibleBitmap(hDC, x, y);
    HBITMAP hResultBmp = NULL;
    HGDIOBJ hOrgBMP = SelectObject(hMemDC, hMemBmp);
    
    DrawIconEx(hMemDC, 0, 0, hIcon, x, y, 0, NULL, DI_NORMAL);
    
    hResultBmp = hMemBmp;
    hMemBmp = NULL;
    
    SelectObject(hMemDC, hOrgBMP);
    DeleteDC(hMemDC);
    ReleaseDC(NULL, hDC);
    DestroyIcon(hIcon);
    return hResultBmp;
    

提交回复
热议问题