Load a CBitmap dynamically

前端 未结 8 1894
情深已故
情深已故 2021-02-06 02:59

I have a Bitmap image that i want to load dynamically. But I am unable to load it.

CBitmap bmp;

bmp.LoadBitmap(\"c:\\\\aeimg\");

it does not

8条回答
  •  Happy的楠姐
    2021-02-06 03:39

    CString filename;
    TCHAR szFilter[] = _T("Bitmap (*.bmp)|*.bmp|PNG (*.png)|*.png||");
    
    CFileDialog selDlg(TRUE, NULL, NULL, OFN_OVERWRITEPROMPT | OFN_EXTENSIONDIFFERENT, szFilter, this);
    
    
    if (selDlg.DoModal() == IDOK)
    {
        filename = selDlg.GetPathName();
    
        CImage image;
    
        HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    
    
        if (hBitmap)
        {
        // Delete the current bitmap
        if (m_bmpBitmap.DeleteObject())
            m_bmpBitmap.Detach();   // If there was a bitmap, detach it
    
        // Attach the currently loaded bitmap to the bitmap object
        m_bmpBitmap.Attach(hBitmap);
    
        Invalidate();
        }
    
    }
    

提交回复
热议问题