当前位置:编程学习 > C/C++ >>

CImageList控件中图象橙色被显示为黄色?

 

 

使用一个CImageList控件来装入位图,用于TREE控件,其它的色彩都很正常就是橙色被显示成为黄色.

 

你只能使用系统指定的20种颜色(橙色不包括在内);当然,你也可以用下面的方法来装载位图资源而不受颜色数的限制.

 

HBITMAP LoadResourceBitmap(HINSTANCE hInstance, LPSTR lpString,

                           HPALETTE FAR* lphPalette)

{

    HRSRC hRsrc;

    HGLOBAL hGlobal;

    HBITMAP hBitmapFinal = NULL;

    LPBITMAPINFOHEADER lpbi;

    HDC hdc;

    int iNumColors;

    if (hRsrc = ::FindResource(hInstance, lpString, RT_BITMAP))

{

  hGlobal = ::LoadResource(hInstance, hRsrc);

  lpbi = (LPBITMAPINFOHEADER)LockResource(hGlobal);

  hdc = ::GetDC(NULL);

  *lphPalette = CreateDIBPalette ((LPBITMAPINFO)lpbi, &iNumColors);

  if (*lphPalette)

  {

   ::SelectPalette(hdc,*lphPalette,FALSE);

   ::RealizePalette(hdc);

  }

  hBitmapFinal = ::CreateDIBitmap(hdc,

       (LPBITMAPINFOHEADER)lpbi,

       (LONG)CBM_INIT,

       (LPSTR)lpbi + lpbi->biSize + iNumColors * sizeof(RGBQUAD),

                   (LPBITMAPINFO)lpbi,

                   DIB_RGB_COLORS );

  ::ReleaseDC(NULL,hdc);

// ::UnlockResource(hGlobal);

// ::FreeResource(hGlobal);

}

    return (hBitmapFinal);

}

 

// internally used by LoadResourceBitmap

HPALETTE CreateDIBPalette (LPBITMAPINFO lpbmi, LPINT lpiNumColors)

{

LPBITMAPINFOHEADER lpbi;

LPLOGPALETTE lpPal;

HANDLE hLogPal;

HPALETTE hPal = NULL;

int i;

lpbi = (LPBITMAPINFOHEADER)lpbmi;

if (lpbi->biBitCount <= 8)

  *lpiNumColors = (1 << lpbi->biBitCount);

else

  *lpiNumColors = 0; // No palette needed for 24 BPP DIB

if (lpbi->biClrUsed > 0)

  *lpiNumColors = lpbi->biClrUsed; // Use biClrUsed

if (*lpiNumColors)

{

  hLogPal = GlobalAlloc (GHND, sizeof (LOGPALETTE) +

   sizeof (PALETTEENTRY) * (*lpiNumColors));

  lpPal = (LPLOGPALETTE) GlobalLock (hLogPal);

  lpPal->palVersion = 0x300;

  lpPal->palNumEntries = *lpiNumColors;

  for (i = 0; i < *lpiNumColors; i++)

  {

   lpPal->pal

PalEntry[i].

peRed = lpbmi->bmiColors[i].rgbRed;

   lpPal->palP

补充:软件开发 , C语言 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,