CDC and BItmap question
-
This code is supposed to draw the bitmap/image to an HDC specified:
image->Draw(hdc);
This was code was ok, and was drawing on CView::OnDraw() Now I want the image to be drawn as an Icon/Thumbnail to a CListBoxCtrl.. This is my code (this code was taken from the CListImageCtrl article..) I get the HBITMAP retunred from the function, then attach it on a CBitmap and then add the CBItmap, and then the icon is supposed to appear on the ListCtrl.. But it doesn't... the original code is like this:IPicture* pPic; OleLoadPicturePath(wpath, NULL, NULL, NULL, IID_IPicture,(LPVOID*)&pPic); ... ... ... HBITMAP hPicRet = (HBITMAP)CopyImage(hPic, IMAGE_BITMAP, nWidth, nHeight , LR_COPYDELETEORG); CDC hdcSrc, hdcDst; hdcSrc.CreateCompatibleDC(NULL); hdcDst.CreateCompatibleDC(NULL); // Load the bitmaps into memory DC CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(hPicRet); CBitmap* hbmDstT = (CBitmap*) hdcDst.SelectObject(hBmReturn); hdcDst.BitBlt(XDest,YDest,nDestWidth, nDestHeight, &hdcSrc,0,0,SRCCOPY); pOldBitmapImage = (HBITMAP)SelectObject(hdcDst.m_hDC,bm); return pOldBitmapImage
This code was ok but I modified this code because IPicture cant handle other image formats to i use an image library.. i replace this code:CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(hPicRet);
with:hdcSrc.CreateCompatibleDC(NULL); image->Draw(hdcSrc.GetSafeHdc());
T The images doesn't appear.. I modified the code based on my understanding of CDC and Bitmaps.. Help please:) "the possibilities are endles..." -
This code is supposed to draw the bitmap/image to an HDC specified:
image->Draw(hdc);
This was code was ok, and was drawing on CView::OnDraw() Now I want the image to be drawn as an Icon/Thumbnail to a CListBoxCtrl.. This is my code (this code was taken from the CListImageCtrl article..) I get the HBITMAP retunred from the function, then attach it on a CBitmap and then add the CBItmap, and then the icon is supposed to appear on the ListCtrl.. But it doesn't... the original code is like this:IPicture* pPic; OleLoadPicturePath(wpath, NULL, NULL, NULL, IID_IPicture,(LPVOID*)&pPic); ... ... ... HBITMAP hPicRet = (HBITMAP)CopyImage(hPic, IMAGE_BITMAP, nWidth, nHeight , LR_COPYDELETEORG); CDC hdcSrc, hdcDst; hdcSrc.CreateCompatibleDC(NULL); hdcDst.CreateCompatibleDC(NULL); // Load the bitmaps into memory DC CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(hPicRet); CBitmap* hbmDstT = (CBitmap*) hdcDst.SelectObject(hBmReturn); hdcDst.BitBlt(XDest,YDest,nDestWidth, nDestHeight, &hdcSrc,0,0,SRCCOPY); pOldBitmapImage = (HBITMAP)SelectObject(hdcDst.m_hDC,bm); return pOldBitmapImage
This code was ok but I modified this code because IPicture cant handle other image formats to i use an image library.. i replace this code:CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(hPicRet);
with:hdcSrc.CreateCompatibleDC(NULL); image->Draw(hdcSrc.GetSafeHdc());
T The images doesn't appear.. I modified the code based on my understanding of CDC and Bitmaps.. Help please:) "the possibilities are endles..."Maverick wrote: hdcSrc.CreateCompatibleDC(NULL); image->Draw(hdcSrc.GetSafeHdc()); When you create a DC via CreateCompatibleDC it does not have a usable drawing surface (memory) associated with it. You have to use SelectObject to select a bitmap drawing surface into it. And be sure to restore the DC back to it's original state before deleting it.
hdcSrc.CreateCompatibleDC(NULL);
CBitmap TempBitmap;
TempBitmap.CreateCompatibleBitmap(hdcDst, image->Width(), image->Height());
CBitmap *pOldBitmap = (CBitmap *)hdcSrc.SelectObject(&TempBitmap);
image->Draw(hdcSrc.GetSafeHdc());
...
hdcSrc.SelectObject(pOldBitmap); // restore old bitmap
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
-
Maverick wrote: hdcSrc.CreateCompatibleDC(NULL); image->Draw(hdcSrc.GetSafeHdc()); When you create a DC via CreateCompatibleDC it does not have a usable drawing surface (memory) associated with it. You have to use SelectObject to select a bitmap drawing surface into it. And be sure to restore the DC back to it's original state before deleting it.
hdcSrc.CreateCompatibleDC(NULL);
CBitmap TempBitmap;
TempBitmap.CreateCompatibleBitmap(hdcDst, image->Width(), image->Height());
CBitmap *pOldBitmap = (CBitmap *)hdcSrc.SelectObject(&TempBitmap);
image->Draw(hdcSrc.GetSafeHdc());
...
hdcSrc.SelectObject(pOldBitmap); // restore old bitmap
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!