Solved

Changing Radio Button Text color

Posted on 2001-06-05
9
3,998 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now