Click to See Complete Forum and Search --> : How can I can the text and background color of CEdit control ?


anuar
April 1st, 1999, 05:57 AM
I create a dialog with a CEdit control in it using resource editor. It work fine. But now I want to change the text and backgroung color .i.e. background black and text is white. Can anybody know how to do this ? Thanks in advance.

Roland Seibert
April 1st, 1999, 07:23 AM
Hi,

the colors of controls in a dialog is controlled by the WM_CTLCOLOR message send to the control. There you can change

the colors of each control. You must return a brush handle. Here some sample if you use MFC:

//this member you create using class wizard

HBRUSH CPassWordDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)

{

// default returns brush, but you can use your own

HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// TODO: Change any attributes of the DC here

if ( pWnd->GetDlgCtrlID( ) == YourControl_ID )

{

pDC->SetTextColor(COLOR_TEXT);

pDC->SetBkColor(COLOR_BACKGND);

hbr = m_Brush; // your own brush for the background of your control

}

// TODO: Return a different brush if the default is not desired

return hbr;

}


Hope this helps

R.Seibert