Saturday, May 19, 2012

Changing the background color of a dialog

November 1, 2009 by · Leave a Comment 

I have found this proper way to set the color of CDialog in MFC application.

Write this Function in your class.

HBRUSH CCaptureOPtionsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if( nCtlColor == 6 ) // for Slider control
{
pDC->SetBkMode(TRANSPARENT);// Set the Background Mode to TRANSPARENT }

else if( nCtlColor == CTLCOLOR_DLG ) // for dialog
{
pDC->SetTextColor(RGB(0, 0, 0)); // set the Text Color; black
pDC->SetBkMode(TRANSPARENT); // Set the Background Mode to TRANSPARENT
m_brush.CreateSolidBrush(RGB(214, 211, 206)); // Set RGB color any you want for your Dialog
}
return m_brush;
}

Top Blogs

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

*