Print Page | Close Window

Load PNG From resource with CodeJock

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=14081
Printed Date: 22 June 2025 at 2:55pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Load PNG From resource with CodeJock
Posted By: barobax
Subject: Load PNG From resource with CodeJock
Date 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.



Replies:
Posted By: rdhd
Date 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);




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net