Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Load PNG From resource with CodeJock
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Load PNG From resource with CodeJock

 Post Reply Post Reply
Author
Message
barobax View Drop Down
Senior Member
Senior Member


Joined: 07 May 2008
Status: Offline
Points: 117
Post Options Post Options   Thanks (0) Thanks(0)   Quote barobax Quote  Post ReplyReply Direct Link To This Post Topic: Load PNG From resource with CodeJock
    Posted: 20 April 2009 at 7:55am
Hi,
which class can load a PNG file from dll resources and make HBITMAP for resource ?!?

I tried CXTPImageManager and CXTPImageIcon and CXTPImageIconHandle but I can't load my resource. I have HINSTANCE handle and when I try to load PNG file with handle The HBITMAP is NULL.

please help me,
Thanks,
Best Regards.
Back to Top
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 931
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Posted: 20 April 2009 at 3:27pm
After we moved to V12 we had problems getting bitmaps. We had to create a CXTPImageManagerIconHandle and call CopyHandle. The input was the CXTPImageManagerIconHandle

CXTPImageManagerIconHandle IconCopy;

IconCopy.CopyHandle(IconHandle);

We could then get the HBITMAP. However, with png files, the returned bitmap was rendered with a black background and I could not find a way to control that. So we then used the CXTPImageManagerIconHandle and createded a compatible DC and drew into the DC. It went something like this:

CDC *pDCSrc = GetDC();

if(pDCSrc)

{

HDC hDCMem = CreateCompatibleDC( NULL );

HBITMAP hBmpOld = 0;

HBRUSH hBrush = CreateSolidBrush( Background );

// create a bitmap that will be used after the

// icon is drawn

hbm = CreateCompatibleBitmap( pDCSrc->m_hDC, nWidth, nWidth );

hBmpOld = (HBITMAP)SelectObject( hDCMem, hbm );

CPoint pt;

pt.x = pt.y = 0;

HBRUSH hBrushOld = (HBRUSH)SelectObject( hDCMem, hBrush );

HPEN hPenOld = (HPEN)SelectObject(hDCMem,GetStockObject(NULL_PEN));

Rectangle( hDCMem, 0, 0, nWidth+1, nWidth+1 );

CSize szIcon;

szIcon.cx = szIcon.cy = nWidth;

bool bDrawComposited = false;

CDC* tmpDC;

tmpDC = CDC::FromHandle( hDCMem );

IconHandle.Draw( tmpDC, pt, szIcon, bDrawComposited );

SelectObject( hDCMem, hBrushOld );

SelectObject( hDCMem, hPenOld );

SelectObject( hDCMem, hBmpOld );

DeleteObject( hBrush );

DeleteDC( hDCMem );

DeleteDC( pDCSrc->m_hDC);

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.031 seconds.