CJ Control for displaying .png |
Post Reply |
Author | |
doinIT
Newbie Joined: 16 March 2009 Location: Australia Status: Offline Points: 8 |
Post Options
Thanks(0)
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
|
|
SuperMario
Admin Group Joined: 14 February 2004 Status: Offline Points: 18057 |
Post Options
Thanks(0)
|
Have you tried the button sample?
|
|
doinIT
Newbie Joined: 16 March 2009 Location: Australia Status: Offline Points: 8 |
Post Options
Thanks(0)
|
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;} |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |