How to use 256 Color Bitmaps in ImageList (Win32 SDK solution)

-->

This is how to use 256(or 16bit, 24bit)-color bitmaps in ImageLists for ListViews, TreeViews, etc...

Usually you use something like this to load/create your imagelist:

hScreens = ImageList_LoadImage(GetModuleHandle(NULL),
 MAKEINTRESOURCE(BMP_SCREENS), 100, CLR_NONE, CLR_NONE, IMAGE_BITMAP,
 LR_LOADTRANSPARENT);

However it will always convert your bitmap to 16 colors or fail. now, simply replace it with this code:
HBITMAP hScrBM;

hScreens = ImageList_Create(100, 70, ILC_COLOR8, 0, 999);
hScrBM = LoadImage(GetModuleHandle(NULL),
 MAKEINTRESOURCE(BMP_SCREENS256), IMAGE_BITMAP, 0, 0,
 LR_LOADTRANSPARENT);

ImageList_Add(hScreens, hScrBM, NULL);

DeleteObject(hScrBM);

Of course, you can use other values instead of ILC_COLOR8 (256color): ILC_COLOR16, ILC_COLOR24, ... (see "ImageList_Create()" online help in VC++)

Hope this helps...



Comments

  • Using hi/truecolor bitmaps in imagelists (MFC solution)

    Posted by Legacy on 02/11/1999 12:00am

    Originally posted by: Bartosz Bien

    Hi,
    
    

    You can also use MFC solution to use hi/truecolor bitmaps in imagelists. The following functions
    do nearly the same that you have achieved using Platform SDK:

    CBitmap::LoadBitmap
    CImageList::Create(int cx, int cy, UINT nFlags, int nInitial, int nGrow)
    CImageList::Add
    CBitmap::DeleteObject

    In CImageList::Create, use ILC_MASK | ILC_COLOR24 (bpp as needed).

    Regards,
    Bartosz Bien

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds