PRB: SelectObject() Fails After ImageList_GetImageInfo() (131279)
The information in this article applies to:
- Microsoft Platform Software Development Kit (SDK) 1.0, when used with:
This article was previously published under Q131279 SYMPTOMS
When you try to select the hBitmap returned by ImageList_GetImageInfo()
into a device context, the call to SelectObject() fails and returns NULL.
CAUSE
Under the debug version of Windows 95, attempting to select the hBitmap
returned by ImageList_GetImageInfo() into a DC causes the GDI to output
the message "Bitmap already selected."
Image lists maintain memory DCs with the image and mask bitmaps already
selected. This is done to prevent applications from modifying the images
contained in the image list that are currently being used by the system.
Because a bitmap cannot be selected into more than one DC at a time,
applications that call SelectObject() on the same bitmap fail.
RESOLUTION
An application can work around this in Windows 95 by calling CopyImage() on
the hBitmap, as demonstrated in the following sample code. This API is new
for Windows 95. Remember to delete the hBitmap copy when using this
function.
Sample Code
HDC hDC;
HBITMAP hBitmap, hOldBitmap;
IMAGEINFO imageInfo;
ImageList_GetImageInfo (hImgList, iWhichImage, &imageInfo);
hBitmap = CopyImage (imageInfo.hbmImage,
IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG);
hOldBitmap = SelectObject(hDC, hBitmap);
:
:
// Delete hBitmap when you finish using it.
DeleteObject (SelectObject (hDC, hOldBitmap));
STATUS
This behavior is by design.
Modification Type: | Minor | Last Reviewed: | 7/11/2005 |
---|
Keywords: | kbCtrl kbImgList kbprb KB131279 |
---|
|