Convert image list to device unlock

zhaozj2021-02-11  214

In my PrintTree example, I want to print colored tree control. It is easy for text, but the icon is

Not simple. I tried to convert the image list into DIB, but I really need a method to take out one

Icon's DIB instead of the entire image list. Below is the specific method I use:

Handle CadvancedTreeCtrl :: ImageTodib (Cimagelist * Pimagelist, Int iimagenumber, CWND * PWND, BOOL BOVERLAY, HTREEITEM ACTUALITEM)

{

// Local Variables

CBitmap Bitmap;

CWindowDC DC (PWND);

CDC MEMDC;

CRECT RECT;

CPALETTE PAL;

ImageInfo imageinfo;

IF (false == pimagelist-> getImageInfo (iimagenumber, & imageinfo))

{

// Getting of the imageinfos failed

Return NULL;

}

// Create Compatible Stuff and SELECT Bitmap

IF (false == memdc.createcompatibledc (& dc))

{

// Create Failed

Return NULL;

}

IF (false == bitmap.createcompatiblebitmap (& DC,

ImageInfo.rcimage.bottom-ImageInfo.rcimage.top,

ImageInfo.rcimage.right-imageinfo.rcimage.Left)))

{

// Create Failed

Return NULL;

}

CBitMap * PoldbitMap = MEMDC.SELECTOBJECT (& Bitmap);

IF (NULL == Poldbitmap)

{

// SELECT FAILED

Return NULL;

}

// Local Variables for Draw

CPoint Point (0, 0);

Uint nStyle = Ild_normal;

// is there an overlay

IF (True == Boverlay)

{

TV_Item TV_Item;

// set up the item-struct

TV_Item.hitem = actualItem;

// Get the full item-struct

GetItem (& TV_Item);

// set the Wanted Style

NStyle = ILD_TRANSPARENT | (TV_Item.State & TV_overlaymask);

}

// Draw Image to the Compatible DC

IF (false == pimagelist-> Draw (& MEMDC, IIMAGENUMBER, POINT, NSTYLE))

{

// Drawing of the image failed

Return NULL;

}

// Create Logical Palette IF Device Support a Palette

IF (DC.GETDEVICECAPS (RasterCaps) & rc_palette

{

UINT nsize = sizeof (slogpalette) * 256); LogPalette * PLP = (logpalette *) New byte [nsize];

PLP-> paversion = 0x300;

PLP-> PALNUMENTRIES = (Unsigned Short) GetsystemPaletteentries (DC, 0, 255,

PLP-> PALPALENTRY

// Create the Palette

PAL.CREATEPALETTTE (PLP);

// free memory

DELETE [] PLP;

}

MEMDC.SELECTOBJECT (POLDBITMAP);

// convert the bitmap to a dib

Return DDBTODIB (Bitmap, Bi_RGB, & PAL);

}

转载请注明原文地址:https://www.9cbs.com/read-3779.html

New Post(0)