Hi! I'm working on an MFC program. I have static text controls that have the standard ugly gray background which I would like to change to something else (like to white or red or blue!). How can I initialize these controls and edit controls to have a given background color in OnInitDialog(). Thanks so much I !!!
I found what looks like a good example here but I can't get it to work for me in just the initialization... http://forums.codeguru.com/showthread.php?t=168927
In this example he uses this line: if(pWnd->GetDlgCtrlID() == IDC_EDIT1) I don't understand what -> means and I can't find any info on it or why he is able to put 2(?) statements in an if clause...
This is the code I currently have for this purpose in OnInitDialog(). I only have 1 main dialog right now:
Tip: read html symbols table and you will know what > (greater than) means.
Regarding your question, process WM_CTLCOLORSTATIC or MFC equivalent message in your parent dialog procedure.
Thanks modoran I'm getting there~
The problem now is that I can't seem to get one specific static control to be the color I want. This code changes the background of every static/edit control I have). Here is what I have so far:
OK I got it ! This will change the color of whatever control I specify.
For anybody else that comes across this here is the updated code:
1 2 3 4 5 6 7 8 9 10 11 12
HBRUSH CDialogDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_NAME_ONE)
{
pDC->SetBkColor(m_backColor);
return (HBRUSH)m_backBrush.GetSafeHandle();
}
return 0;
//'return hbr;' will make every control the color of the brush...
}