PRB: SelectObject() Fails After ImageList_GetImageInfo()Last reviewed: September 29, 1995Article ID: Q131279 |
The information in this article applies to:
SYMPTOMSWhen you try to select the hBitmap returned by ImageList_GetImageInfo() into a device context, the call to SelectObject() fails and returns NULL.
CAUSEUnder 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.
RESOLUTIONAn 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));
STATUSThis behavior is by design.
|
Additional reference words: 4.00 unusable hDC Image Lists beta
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |