Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Controls
  New Posts New Posts RSS Feed - Buttons lose rounded edges - OnPaint background
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Buttons lose rounded edges - OnPaint background

 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: Buttons lose rounded edges - OnPaint background
    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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
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: 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
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.141 seconds.