Solved

Changing Radio Button Text color

Posted on 2001-06-05
9
4,045 Views
Last Modified: 2013-11-20
I wish to change the color of the textof a radio button when the mouse is aronud it.
I catch the WM_MOUSEMOVE and then I set focus on the button. yet I can't find the way to change the button color, and how to make the background of the button transparent (I wish only the text and the radio circle to be visiable)

The button was derived from CButton , and is created on a dialogbox with create function, during oninitialize, with radio button style.

I've tried to catch WM_CTLCOLOR in the dialog class (the parnet of the buttons) but if I set the Button's text color there, it sets all the radio buttons I've created inspite the if statement I put there to change only a single button. (the if works since I've notice that if I change the first button it effects all the rest and if I change the 2nd, none are effected).
the SetBKmode(Transparent) did nothing to the buttons.

So basicly I need 2 things - the change text color, and how to make the background transparent.

thanks in advance.

Dani

0
Comment
Question by:KaplanDani
9 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
ID: 6158222
There are several implementations fo so-called "hover buttons" here:

http://codeguru.earthweb.com/buttonctrl/index.shtml

This one looks particularly promising:
http://codeguru.earthweb.com/buttonctrl/hover_button.shtml

But it looks like they all make you create several bitmaps (ala web page mouse-over buttons).

It sound like you have already created a class for the hover buttons.  I think that all you need to do is add a message map entry for handler for that class.

ON_WM_CTLCOLOR_REFLECT()

and a hndler like so:

HBRUSH CMyRadioBtn::CtlColor(CDC* pDC, UINT nCtlColor)
{
   if ( nCtlColor= nIdTheButtonBeingHovered ) {
     // set the hover colors
   }
   else {
     // set the non-hover colors
   }
   return NULL;    // (or brush to use)
}

-- Dan
0
 
LVL 2

Author Comment

by:KaplanDani
ID: 6160470
There is no ON_WM_CTLCOLOR_REFLECT on the MSDN.
I've found how to chnage the radio button text color - I set the style to BS_OWNERDRAW and the ctlcolor works.
But still I need to find a way to make the background transparent.
(i want to see only text and a circle).
The site you quoted uses load bitmap and I don't want to use that method.
0
 

Expert Comment

by:alortiz
ID: 6160847
The propperties you are looking for, are inherited from CWindow
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 49

Expert Comment

by:DanRollins
ID: 6161105
oops, ON_WM_CTLCOLOR_REFLECT is obsolete

I found it in..
http://msdn.microsoft.com/library/periodic/period96/S1DCC.htm

details about it hare here:

HOWTO: Change the Color of an MFC Child Control Class
http://support.microsoft.com/support/kb/articles/Q132/0/80.asp

To do transparent drawing, try setting

CDC.SetBkMode( TRANSPARENT );

-- Dan

0
 
LVL 1

Expert Comment

by:jizhang
ID: 6182047
Hi there,

If you want to set a BT text a color,  you need to
tell which BT --   swich  GetDlgCtrlID() {case ..};

For example, set BT 1,3,5:

HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
     HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
     
     // TODO: Change any attributes of the DC here
     int nID = pWnd->GetDlgCtrlID();
        switch (nID)
        {
        case IDC_RADIO1:
                pDC->SetTextColor(RGB(0xff, 0, 0));
                break;
        case IDC_RADIO3:
                pDC->SetTextColor(RGB(0, 0, 0xff));
                break;
        case IDC_RADIO5:
     pDC->SetTextColor(RGB(0,0xff,0));
     break;
     default:
     break;
        }
     
     // TODO: Return a different brush if the default is not desired
     return hbr;
}

Ji Zhang
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6320342
hi for KaplanDani,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6686656
hi for KaplanDani,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
LVL 11

Expert Comment

by:griessh
ID: 7202168
Unless there is objection or further activity,  I will suggest to accept

     "DanRollins"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7220553
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question