Click here to Skip to main content
15,919,500 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have some radio buttons (CButtons) which I have placed in a CWnd which is then diplayed on a CDialog.

The background colour of the radio button is black, not the usual windows dialog background colour. How can I make the background colour of the radio button in the CWnd the same as the background colour of the CDialog?

This is my code to create the CWnd and the radio buttons:

CWnd *ctlGroupBox = new CWnd;
CButton *rdo1 = new CButton;
CButton *rdo2 = new CButton;

ctlGroupBox->Create(_T("BUTTON"),
		_T("Pizza Size"),
		WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
		CRect(50, 10, 200, 160),
		this,
		15);

rdo1->Create(_T("Large1"),
	        WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
	        CRect(40, 80, 120, 140), ctlGroupBox, 0x16);
rdo2->Create(_T("Large2"),
	        WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                CRect(40, 130, 120, 140), ctlGroupBox, 0x16);
Posted
Updated 7-Jun-11 3:41am
v3

Don't you want to use CRadioButton instead of CButton?
 
Share this answer
 
v2
Comments
Manfred Rudolf Bihy 7-Jun-11 10:11am    
Sounds reasonable enough! 5+
Albert Holguin 7-Jun-11 11:57am    
CRadioButtons don't exist
Albert Holguin 7-Jun-11 11:55am    
there's no such thing in C++/MFC, a radio button is a CButton with the radio property
derive a class from CButton and do code in ON_WM_ERASEBKGND()
example:
class CMyButton : public CButton
{
    DECLARE_DYNAMIC(CMyButton)
public:
    CMyButton();
    virtual ~CMyButton();
protected:
    DECLARE_MESSAGE_MAP()
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    afx_msg void OnPaint();
};

// CMyButton
IMPLEMENT_DYNAMIC(CMyButton, CButton)
CMyButton::CMyButton()
{
}
CMyButton::~CMyButton()
{
}
BEGIN_MESSAGE_MAP(CMyButton, CButton)
    ON_WM_ERASEBKGND()
    ON_WM_PAINT()
END_MESSAGE_MAP()
// CMyButton message handlers
BOOL CMyButton::OnEraseBkgnd( CDC* pDC )
{
    CRect Rect;
    GetClientRect( Rect );
    pDC->FillSolidRect( Rect, RGB( 255, 0, 0));
    return TRUE;
}
void CMyButton::OnPaint()
{
    CPaintDC dc(this); // device context for painting
    // TODO: Add your message handler code here
    // Do not call CButton::OnPaint() for painting messages
}
 
Share this answer
 
Comments
Jackie Lloyd 11-Jun-11 6:22am    
Hi - many thanks for this. I have only just tried your suggestion as been in hospital this week. It has coloured the rectangle where my radio button is which is great, but it has coloured over my radio button so I can no longer see it. How do I get the radio button ontop of the coloured rectangle?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900