Print Page | Close Window

Buttons lose rounded edges - OnPaint background

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Controls
Forum Description: Topics Related to Codejock Controls
URL: http://forum.codejock.com/forum_posts.asp?TID=13698
Printed Date: 12 December 2024 at 12:31pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Buttons lose rounded edges - OnPaint background
Posted By: doinIT
Subject: Buttons lose rounded edges - OnPaint background
Date Posted: 16 March 2009 at 2:37am
I created an MFC Dialog app and used the vista skin which is working.
After finding out from another post that the skin builder/framework doesn't included background images for dialogs, I used the OnPaint routine of the main dialog and paint a background gradient image (from a physical .jpeg on disk) using CImage.
 
Problem is after I paint the background image, the buttons on the Dialog lose the round edges. Looks like they can no longer handle the transparecy of the images.
 
Anyone know why this would happen?
 
Thanks,
 
Jai



Replies:
Posted By: Oleg
Date Posted: 16 March 2009 at 8:11am
Hi,
Search in this forum. There was some samples how to draw transparent dialog.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: doinIT
Date Posted: 16 March 2009 at 6:32pm
Thanks Oleg.
 
For others,  here is a bit of an explanation and the code that fixed my problem.
 
I needed to handle the OnCtlColor method and return the brush to be used as the background for the control to be painted.
 
Inside the OnPaint method I draw a gradient jpeg image that fits the entire background of the Dialog.
 
I had to use use the same image that was used to paint the background to create a brush inside OnCtlColor (shown below) which fixed the problem of the buttons losing the transparency.
 
 
HBRUSH CSkinDlgDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)

{

HBRUSH hbr;

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

{

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);

::SetTextColor(hDC, GetSysColor(COLOR_BTNTEXT));

}

}

return m_brush;

}

else

{

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

}

return hbr;

}

 

Cheers,

Jai



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