Search code examples
visual-c++mfcimagelistctabctrl

Using a 24 bit BMP with CTabCtrl


I am trying:

m_imgList.Create(32, 32, ILC_COLOR24 | ILC_MASK, 4, 4);

CBitmap bmp;
bmp.LoadBitmap(IDB_BMP_DATABASE_REPORT_VIEWER);
theApp.SetBitmapBackgroundAsMenuColour(bmp);

m_imgList.Add(&bmp, RGB(47, 47, 47));  // Replace with the correct transparent color

m_tabPreview.SetImageList(&m_imgList);
m_tabPreview.SetItemSize(CSize(0, 34));

I am almost there, but look:

enter image description here

It seems that the tab with focus does not necessarily have the right background colour for the icon.

I am confused.


Based on the suggestions, I have tried using a 32 bit PNG file instead:

// Create the image list and load the bitmap
m_imgList.Create(32, 32, ILC_COLOR32, 4, 4);

CPngImage png;
png.Load(IDB_PNG_MAIN_TOOLBAR, AfxGetResourceHandle());
m_imgList.Add(static_cast<HICON>(png.Detach()));

m_tabPreview.SetImageList(&m_imgList);
m_tabPreview.SetItemSize(CSize(0, 34));

But I am not seeing any icons now.


Solution

  • This works:

    // Create the image list and load the bitmap
    m_imgList.Create(32, 32, ILC_COLOR32, 4, 4);
    
    CPngImage png;
    png.Load(IDB_PNG_MAIN_TOOLBAR, AfxGetResourceHandle());
    
    CBitmap bmp;
    bmp.Attach(png.Detach());
    m_imgList.Add(&bmp, nullptr);
    

    enter image description here