Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC
  New Posts New Posts RSS Feed - CJ Control for displaying .png
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Forum LockedCJ Control for displaying .png

 Post Reply Post Reply
Author
Message
doinIT View Drop Down
Newbie
Newbie


Joined: 16 March 2009
Location: Australia
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote doinIT Quote  Post ReplyReply Direct Link To This Post Topic: CJ Control for displaying .png
    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
 
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 27 March 2009 at 1:10pm
Have you tried the button sample?
Back to Top
doinIT View Drop Down
Newbie
Newbie


Joined: 16 March 2009
Location: Australia
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote doinIT Quote  Post ReplyReply Direct Link To This Post 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;

}

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.125 seconds.