Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

256 color in CListCtrl

Posted on 1998-08-31
3
Medium Priority
?
439 Views
Last Modified: 2013-11-19
Hi,
I have CTreeCtrl within a dialog box and I want to use 256 color bitmaps that a stored in a CImageList. But everything I tried seemed
not to work. The Images are allways displayed  in gray.

Does anybody have a solution for this problem?

Thanx in advance,
 Tom

0
Comment
Question by:stzclaus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
motigust earned 300 total points
ID: 1321492
Hi Stzclaus,

The problem is that you have needs to adjust the palette of your conrol to handle the 256 colors Bitmaps.

You should to write a program that gets the colors from the bitmap and creates a palette.

Then select the palette, and realize it, it should look something like this:
   GetBitmapAndPalette(IDB_1,&MyBitmap,Palette);
   dc.SelectPalette( &palette, FALSE );
   dc.RealizePalette();

The function that gets the plette from the bitmap should be somthing like this:

BOOL CMyClass::GetBitmapAndPalette(UINT nIDResource, CBitmap &bitmap, CPalette &pal)
{
      LPCTSTR lpszResourceName = (LPCTSTR)nIDResource;

      HBITMAP hBmp = (HBITMAP)::LoadImage( AfxGetInstanceHandle(),
                  lpszResourceName, IMAGE_BITMAP, 0,0, LR_CREATEDIBSECTION );

      if( hBmp == NULL )
            return FALSE;

      bitmap.Attach( hBmp );

      // Create a logical palette for the bitmap
      DIBSECTION ds;
      BITMAPINFOHEADER &bmInfo = ds.dsBmih;
      bitmap.GetObject( sizeof(ds), &ds );

      int nColors = bmInfo.biClrUsed ? bmInfo.biClrUsed : 1 << bmInfo.biBitCount;

      // Create a halftone palette if colors > 256.
      CClientDC dc(NULL);                  // Desktop DC
      if( nColors > 256 )
            pal.CreateHalftonePalette( &dc );
      else
      {
            // Create the palette

            RGBQUAD *pRGB = new RGBQUAD[nColors];
            CDC memDC;
            memDC.CreateCompatibleDC(&dc);

            memDC.SelectObject( &bitmap );
            ::GetDIBColorTable( memDC, 0, nColors, pRGB );

            UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);
            LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];

            pLP->palVersion = 0x300;
            pLP->palNumEntries = nColors;

            for( int i=0; i < nColors; i++)
            {
                  pLP->palPalEntry[i].peRed = pRGB[i].rgbRed;
                  pLP->palPalEntry[i].peGreen = pRGB[i].rgbGreen;
                  pLP->palPalEntry[i].peBlue = pRGB[i].rgbBlue;
                  pLP->palPalEntry[i].peFlags = 0;
            }

            pal.CreatePalette( pLP );

            delete[] pLP;
            delete[] pRGB;
      }

      return TRUE;
}



Have fun,

      Moti  :-)

0
 

Author Comment

by:stzclaus
ID: 1321493
Hi Moti,

Thank you for your answer. I've tried the code you gave me, but the bitmaps still appear in grayscale. I don't know exactly what else is wrong in my code.
Maybe you could help me with the following questions.
 How do I have to create the CImageList?
   I use: pMyImageList->Create(IDB_BLABLA,XX,Y,0)
   Maybe I should use pMyImageList->Create(x,x ILC_COLOR8,x,x) ??
   If I do so, do I have to Add every Bitmap I want to use? And how do I get the Bitmap? With the    same function you gave to me?

To what DC do I have to select the pallet?
 I tried  CClientDC myDC (this) and CClientDC myDC (NULL)
Is this wrong?

It would be great, if you could help me!

Many, many thanx in advance

Tom

0
 

Author Comment

by:stzclaus
ID: 1321494
Hi Moti!

It works!

I think the only problem was, that I used the wrong create-function for my CImageList.
I tried Create(x,x ILC_COLOR8,x,x), Add (IDB_IMAGEWHATSOEVER,xx ) and everything was fine. I didn't even had to create or add a pallete!

Anyway thank you for your troubles!

Tom


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question