Print Page | Close Window

CJ Control for displaying .png

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Visual C++ MFC
Forum Description: Topics related to Codejock Visual C++ MFC products
URL: http://forum.codejock.com/forum_posts.asp?TID=13826
Printed Date: 11 December 2024 at 4:10pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CJ Control for displaying .png
Posted By: doinIT
Subject: CJ Control for displaying .png
Date Posted: 27 March 2009 at 2:46am
Hi,
 
Whats the best control to use for displaying a transparent .png file over top of a background image.
 
I paint a custom .png file to the background of a dialog inside onpaint and have successfully used the OnCtlColor routine to return the correct brush to make the CJ buttons transparent, but I'd like to know the best control to paint a transparent image.
 
I've tried using the standard MFC CStatic class, but the transparency isn't working with CStatic::SetBitmap
 
Thanks,
 
Jai
 



Replies:
Posted By: SuperMario
Date Posted: 27 March 2009 at 1:10pm
Have you tried the button sample?


Posted By: doinIT
Date Posted: 29 March 2009 at 8:24pm
Hi SuperMario,
 
Yeah, I've looked at the button sample and have tried it in my own app. It works ok, but I can still faintly see the outline of the button even though it is being rendered transparently in flat style.
 
It's as if the background of the button isn't getting the right brush offset of the background image. I've posted my OnCtlColor routine if you can see anything that looks off.
 

HBRUSH CHDMSDiag::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)

{

HBRUSH hbr;

 

if( nCtlColor == CTLCOLOR_STATIC || nCtlColor == CTLCOLOR_BTN || nCtlColor == CTLCOLOR_DLG || nCtlColor == CTLCOLOR_EDIT )

{

if(img){

m_brush = CreatePatternBrush(img); // Previously created CImage

if (pWnd->m_hWnd != this->m_hWnd)

{

CXTPWindowRect rcPaint(pWnd);

CXTPWindowRect rcBrush(m_hWnd);

HDC hDC = pDC->m_hDC;

::SetBrushOrgEx(hDC, rcBrush.left - rcPaint.left, rcBrush.top - rcPaint.top, NULL);

::SetBkMode(hDC, TRANSPARENT);

if(nCtlColor == CTLCOLOR_STATIC){

if(pWnd->m_hWnd != this->GetDlgItem(IDC_DRIVE2_ICON)->GetSafeHwnd()

&& pWnd->m_hWnd != this->GetDlgItem(IDC_DRIVE1_ICON)->GetSafeHwnd()

&& pWnd->m_hWnd != this->GetDlgItem(IDC_DRIVE_1)->GetSafeHwnd()){

pDC->SetBkMode(TRANSPARENT);

::SetTextColor(hDC, RGB(255, 255, 255));

return (HBRUSH)GetStockObject(NULL_BRUSH);

}else

int test = 0;

}

else

::SetTextColor(hDC, RGB(255, 255, 255));

}

}

return m_brush;

}

else

{

hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

}

return hbr;

}




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