Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Extract a CBitmap from a CImageList

Posted on 1998-04-17
2
Medium Priority
?
1,347 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 400 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

661 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