Link to home
Start Free TrialLog in
Avatar of b_yousif
b_yousif

asked on

changing the caption color of a Button

is there an easy way to change the color of the caption on a button control.....
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
one more thing: dont forget to change the type of your buttons to CColorButton.

:~)
what do you mean with "caption" of a button?
A frame window can have a caption.
Do you want to change the textcolor of the button title ?

please be more specific.
Avatar of b_yousif
b_yousif

ASKER

yes Pacman, what i ment that i need to change the textcolor of of the button; if u go to the properties of push button in any dialog, there is a field called caption; i need to change the color of this.
do u have more direct way than sedgwick's one ?
he means 2 change the text color !!!
b_yousif: did u try my comment???
Yes there is a simpler solution.
Before a control is drawn in a dialog, the dialog is asked to set the color for the control.

example:

// the following function makes the static text
// with the ID IDC_FARBTEXT red
// it should also work with buttons ...
// to add the function you can use class wizard's
// "add virtual function..."


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

    if ( nCtlColor==CTLCOLOR_STATIC )
    {
        if ( GetDlgItem( IDC_MYTEXT)->GetSafeHwnd() == pWnd->GetSafeHwnd() )
            pDC->SetTextColor( RGB( 255, 0, 0 ) );
    }

    return hbr;
}

sorry, IDC_FARBTEXT is not correct.
Must be IDC_MYTEXT
you may also use CTLCOLOR_BTN instead of CTLCOLOR_STATIC ...

Pacman: did u try it yourself befor posting that comment?
its not working on buttons dude!
b_yousif: post your e-mail and i'll send u a smpale
>> its not working on buttons dude!

oops, you're right.
but it was worth a try ...

Pacman
my e-mail is b_yousif@hotmail.com
it will be nice to get a sample.
you know when i asked this i thought that there is a way to do this using one of the member functions, some one that i didn't find in CButton.
any way i'm waiting for ur sample.