-
April 10th, 2000, 08:31 AM
#1
How to change all background colors for controls in a dialog box
Hi everybody,
Here's my problem : in a dialog based application, how can I change the text and background color of all the controls in the dialog box ?
I don't want to change the colors for each control : if I erase one of them in the dialog resource, I have to do the same in the code. I have searched around the OnCtlColor function, but it doesn't work at all. Here is the standard implementation for that function :
HBRUSH MyDlgClass::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
}
Instead of that code, I've tried to do something like this :
{
CBrush br;
br.CreateSolidBrush(RGB(255, 0, 0)); // Red color
return (HBRUSH) br;
}
Why this code doesn't colorize the controls in red ?
This code produces the right behaviour :
{
if(nCtlColor == CTLCOLOR_EDIT)
Beep(100, 10); // Multiple beep sounds are produced when the dialog appears and one beep is
// produced when a control gets the focus
}
But why returning my personal brush doesn't work ?
Thanks a lot !
-
April 10th, 2000, 08:55 AM
#2
Re: How to change all background colors for controls in a dialog box
You should change the contents of the CDC pointer. Eg. pDC->SetBkColor(RGB(255,0,0));
However, for buttons, this doesn't work. I think the buttons have their own OnCtlColor ... Only way around that is to make them custom (I think - but I might be wrong)
Rune Stampe Nielsen - CERN Genève
-
April 10th, 2000, 11:40 AM
#3
Re: How to change all background colors for controls in a dialog box
In my application I have the brush which I returned as a part of the control I handle CTLCOLOR in; that is, it is not local to that function. My code looks pretty much exactly the same as yours...
HBRUSH MyControl::CtlColor(CDC* pDC, UINT nCtlColor)
{
pDC->SetBkMode(TRANSPARENT); // My brush is a null brush;
// I have a bitmap on the background I want visible...
return HBRUSH(m_MyBackGroundBrush);
}
as you can see, m_MyBackGroundBrush doesn't go out of scope at the end of the function...
James
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|