Solved

Extract a CBitmap from a CImageList

Posted on 1998-04-17
2
1,262 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
deburging in oracle form 12 87
Change owner from userA to server Local Administrators 7 59
matchUp  challenge 6 52
Path of Workbook 3 59
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

932 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

8 Experts available now in Live!

Get 1:1 Help Now