[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4158
  • Last Modified:

Changing Radio Button Text color

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
KaplanDani
Asked:
KaplanDani
1 Solution
 
DanRollinsCommented:
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
 
KaplanDaniAuthor Commented:
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
 
alortizCommented:
The propperties you are looking for, are inherited from CWindow
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DanRollinsCommented:
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
 
jizhangCommented:
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
 
DanRollinsCommented:
hi for KaplanDani,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
DanRollinsCommented:
hi for KaplanDani,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
griesshCommented:
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
 
MindphaserCommented:
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now