一个对话框程序, 放了一个CStatic控件
pst=(CStatic*)GetDlgItem(IDC_STATIC_PIC);
pst->ModifyStyle(0xF,SS_BITMAP|SS_CENTERIMAGE);m_imageList.Create(IDB_ToolBar, 37, 0, RGB(0,0,0));IMAGEINFO FAR *pImageInfo = NULL ;
pImageInfo = new IMAGEINFO;
if (!m_imageList.GetImageInfo(3, pImageInfo))
{
return false;
}
HBITMAP hbitmap = pImageInfo->hbmImag;
pst->SetBitmap(hbitmap);
没有显示图像, 但是用下面
CBitmap bitmap;
bitmap.LoadBitmap(IDB_ToolBar);
HBITMAP hbitmap = bitmap.operator HBITMAP( );
pst->SetBitmap(hbitmap);
这样子就能显示, 为什么用GetImageInfo就不行了? 谢谢

解决方案 »

  1.   

    PRB: SelectObject() Fails After ImageList_GetImageInfo() Q131279
    --------------------------------------------------------------------------------
    The information in this article applies to:Microsoft Win32 Software Development Kit (SDK), used with:
    Microsoft Windows 95--------------------------------------------------------------------------------
    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. Additional query words: unusable hDC Image Lists beta Keywords : kbCtrl kbImgList kbOSWin2000 kbSDKWin32 kbGrpDSUser kbOSWin95 
    Issue type : kbprb 
    Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch 
    Last Reviewed: December 31, 2000
    © 2001 Microsoft Corporation. All rights reserved. Terms of Use.
     --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources