controls

Hi All,
i have a dialog based app
i set the background of it to be white.
i add 2 new controls. Static and Progress Bar
i want these 2 controls to be white background...

how should i do that ?

Shay
LVL 3
Shay050799Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WynCommented:
handle OnCtlColor

Wyn
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shay050799Author Commented:
i m not subclass them
they are class members
0
WynCommented:
Here I cite:
afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor );

Return Value

OnCtlColor must return a handle to the brush that is to be used for painting the control background.

Parameters

pDC

Contains a pointer to the display context for the child window. May be temporary.

pWnd

Contains a pointer to the control asking for the color. May be temporary.

nCtlColor

Contains one of the following values, specifying the type of control:

CTLCOLOR_BTN   Button control


CTLCOLOR_DLG   Dialog box


CTLCOLOR_EDIT   Edit control


CTLCOLOR_LISTBOX   List-box control


CTLCOLOR_MSGBOX   Message box


CTLCOLOR_SCROLLBAR   Scroll-bar control


CTLCOLOR_STATIC   Static control
Remarks

The framework calls this member function when a child control is about to be drawn. Most controls send this message to their parent (usually a dialog box) to prepare the pDC for drawing the control using the correct colors.

To change the text color, call the SetTextColor member function with the desired red, green, and blue (RGB) values.

To change the background color of a single-line edit control, set the brush handle in both the CTLCOLOR_EDIT and CTLCOLOR_MSGBOX message codes, and call the CDC::SetBkColor function in response to the CTLCOLOR_EDIT code.

OnCtlColor will not be called for the list box of a drop-down combo box because the drop-down list box is actually a child of the combo box and not a child of the window. To change the color of the drop-down list box, create a CComboBox with an override of OnCtlColor that checks for CTLCOLOR_LISTBOX in the nCtlColor parameter. In this handler, the SetBkColor member function must be used to set the background color for the text.

Note   This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.
Regards
Wyn


0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

WynCommented:
>>i m not subclass them
>>they are class members

yes,no need to subclass it.Common controls also send this message to their parent(dialogue).
Wyn
0
WynCommented:
You can also use message-reflect.

Now I will back home and write an example ,wait a minute.
0
Shay050799Author Commented:
where am i suppose to put this message  then ????
0
WynCommented:
for example:
//first you create the Brush or from //stock
m_MyBrush.CreateSolidBrush(RGB(255,255,255));

HBRUSH CMyDlg::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor)
{
if(nCtlColor == CTLCOLOR_EDIT)
{
    return m_MyBrush;
}
}

//later delete after you dont use it.
0
WynCommented:
for example:
//first you create the Brush or from //stock
m_MyBrush.CreateSolidBrush(RGB(255,255,255));

HBRUSH CMyDlg::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

if(nCtlColor == CTLCOLOR_EDIT)
{
    return m_MyBrush;
}
return hbr;
}

//later delete after you dont use it.
0
WynCommented:
Okay:

1:Using class wizard, map the message WM_CTLCOLOR to the CMyDlg.( you can find there in your dialog class under classwiard)

2:Add function like above.

free to ask
Regards
Wyn
 
0
WynCommented:
BTW:you should use class wizard to add your control variables.
0
WynCommented:
For Progress Bar ,the same apply.
Use pWnd->GetDlgCtrlID() == IDC_YOURPgbar to check the control.

BTW:above the CTLCOLOR_EDIT is an example ,you can substitute for another,static.....Read above specification I cite.
Good Luck
Wyn  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.