Solved

Extract a CBitmap from a CImageList

Posted on 1998-04-17
2
1,306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

710 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