Solved

Extract a CBitmap from a CImageList

Posted on 1998-04-17
2
1,248 Views
Last Modified: 2013-11-20
I've used the resource editor to specify a toolbar-like bitmap (that is, it has about 30 images all concatenated together).

I then use the CImageList.Create() function to load that resource and turn it into an image list for use with tree and list controls, etc:

Create(UINT nBitmapID, int cx, int nGrow, COLORREF crMask);

Problem is, I can't see a way to get an individual CBitmap out of the image list for a specific image; that is,

CBitmap bmpToExtract;
RetrieveBitmap(CImageList *myList, UINT iImageNumber, &bmpToExtract);

The GetImageInfo() function apparently retrieves the entire bitmap, not just a bitmap for the image I want to extract.

I sure hope there's any easy answer I'm blindly missing....

Thanks,

--JWimbish
0
Comment
Question by:JSW
2 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 100 total points
ID: 1300213
HBITMAP CImageListEx::GetImageBitmap(int i)
{
IMAGEINFO imInfo;

// get screen DC
CDC *pDC = CDC::FromHandle(::GetDC(NULL));

// use GetImageInfo to get image size, since all images have the // same size use 0 index
BOOL res  = GetImageInfo(0, &imInfo);

if( res == NULL )
      return NULL;
      
CSize imSize = CSize(imInfo.rcImage.right - imInfo.rcImage.left,
            imInfo.rcImage.bottom - imInfo.rcImage.top );

// create compatible DC, bitmap, selecting bitmap into memory DC
// and force image list to draw desired image onto memory DC
CDC memDC;
memDC.CreateCompatibleDC(pDC);
HBITMAP hBm = ::CreateCompatibleBitmap(pDC->GetSafeHdc(), imSize.cx, imSize.cy);
HBITMAP hOldBm = (HBITMAP)::SelectObject(memDC.GetSafeHdc(), hBm);
Draw(&memDC, i, CPoint(0, 0), ILD_NORMAL);
::SelectObject(memDC.GetSafeHdc(), hOldBm);

// return bitmap      
return hBm;

}
0
 

Author Comment

by:JSW
ID: 1300214
Many thanks for the timely answer! I've tried it and it does the trick.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now