Show CBitmap problem CImageList

Category: VC/MFC -> Foundation Classes Author: oppo237 Date: 2005-12-25 16:47:12
 
oppo237
2005-12-25 16:47:12
# define   PICHEGITH   11
# define   PICWIDTH     18

void   CTestDlg :: ImageList_to_Bitmap (CBitmap   * pBitmap,   int   index)
{     
        CImageList   * pImg   =   new   CImageList;
        CBitmap   Bitmap;
        BOOL   bTest   =   Bitmap.LoadBitmap (IDB_TESTWORK);
       
        CImageList   ImgList  ;
        pImg- > Create (PICWIDTH,   PICHEGITH,   ILC_COLOR24 | ILC_MASK,   6,   1);
          BOOL   bOk   =   pImg- > Add (& Bitmap, RGB (192,192,192))  ;

        if (! pImg)
                return;
        IMAGEINFO       imageinfo;      
        pImg- > GetImageInfo (index, & imageinfo);      
        BITMAP       bitmap;      
        CBitmap :: FromHandle (imageinfo.hbmImage) - > GetBitmap (& bitmap);          
        pBitmap- > CreateBitmapIndirect (& bitmap);      
}

void   CTestDlg :: OnPaint ()  
{
        CPaintDC   dc (this);
        CDC   dcMem;
        dcMem .CreateCompatibleDC (& dc);

        CBitmap   bmp;
        ImageList_to_Bitmap (& bmp,   1) ;
        dcMem.SelectObject (& bmp);
        dc.BitBlt (0,0,1000,1000, & dcMem, 0,0, SRCCOPY);
        dcMem.DeleteDC ();
}

Why not show up ?
linng106
2005-12-25 16:52:04
ImageList_to_Bitmap (& bmp,   1);
you total it only adds to the ImageList inside an image in ImageList_to_Bitmap inside , but where is the image index number 1 ? Try it changed to 0 .
xej736781594
2005-12-25 17:03:29
ImageList_to_Bitmap () BITMAP object functions in
GetBitmap obtained free of bitmap bits of information that you can use CImageList :: Draw () to plot , of course, require DC , you can modify ImageList_to_Bitmap function , you need to add a CDC parameters
wangmin_gz
2005-12-25 17:06:16
function less sentence
OnPaint ()
{
CPaintDC   dc (this);
                CDC   dcMem;
                dcMem.CreateCompatibleDC (& dc);
                CBitmap   bmpTemp;
                bmpTemp.CreateCompatibleBitmap (& dc ,   PICWIDTH,   PICHEGITH);
                dcMem.SelectObject (& bmpTemp);
                //   CBitmap   bmp;
                //   bmp.LoadBitmap (IDB_TESTWORK);
                CBitmap   bmp;
                ImageList_to_Bitmap (& bmp,   1);
                dcMem.SelectObject (& bmp);
                dc.BitBlt (0,0,1000,1000, & dcMem, 0,0, SRCCOPY);
dcMem.DeleteDC ();
}
out all black ? Is there any way to solve ?
wuxi100
2005-12-25 17:24:24
ImageList_to_Bitmap (& bmp,   0);

effect is the same if CImageList :: Draw () can be made, but because the picture is RGB (192,192,192) for the background , Add (& Bitmap, RGB (192,192,192)) , and if CDC is only temporary , and the CDC conducted TextOut operation , then BitBlt to the real DC , then the picture of the background in the output when will become black , because the CDC SelectObj (& bmpTemp) bmpTemp is empty pieces of painting , the default is black ?