VC中显示ICON和BMP图片

时间:2022-07-02 15:24:35

显示ICON图标,如下:

static HICON hIcon  = (HICON)::LoadImage(      AfxGetInstanceHandle(),   
    TEXT("1.ico"),  
    IMAGE_ICON,  
    0, 0,  
    LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE);  
  
    CClientDC dc(this);  
    dc.DrawIcon( 350,150,hIcon);

显示bmp位图,如下:

static HBITMAP hBitmap = (HBITMAP)::LoadImage(      NULL,       TEXT("1.bmp"),       IMAGE_BITMAP,       50, 50,       LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE);    CBitmap bmp;  bmp.m_hObject = hBitmap;    CDC memDC;//使用兼容位图DC  memDC.CreateCompatibleDC(GetDC());  memDC.SelectObject(bmp);    BITMAP bmpInfo;  bmp.GetBitmap(&bmpInfo);    bool ret = dc.BitBlt(350,200,bmpInfo.bmWidth,bmpInfo.bmHeight,&memDC,0,0,SRCCOPY);  //透明位图  //dc.TransparentBlt(350,200,bmpInfo.bmWidth,bmpInfo.bmHeight,&memDC,                     //0,0,bmpInfo.bmWidth,bmpInfo.bmHeight,RGB(255,255,255));