Solved

Is it a radio button? In OnCommand

Posted on 2006-11-01
4
302 Views
Last Modified: 2013-11-20
I'm watching for messages in OnCommand, looking for BN_CLICKED and others. I need to know if the BN_CLICKED has been sent by a radio button or something else. How can I do that? I did try the following, but it wasn't successful.

BOOL CMyPage::OnCommand(WPARAM wParam, LPARAM lParam)
{
      WORD lCmdMsg = HIWORD(DWORD(wParam));
      if (lCmdMsg == BN_CLICKED)
      {
            // Was that a radio or check box button?
            CWnd *wnd = GetDlgItem(LOWORD(wParam));
            if (wnd)
            {
                  DWORD style = wnd->GetStyle();
                  if (style & BS_CHECKBOX)
                        myCBFunc(); // it's a check box
                  else if (style & BS_RADIOBUTTON)
                        myRBFunc(); // THIS NEVER GETS HIT
            }
      }
      
      return CPropertyPage::OnCommand(wParam, lParam);
}
0
Comment
Question by:ManAtNext
4 Comments
 
LVL 4

Expert Comment

by:bdunz19
ID: 17851139
Hi, I'm not certain, but I would try just comparing the LOWORD(wParam) to the control id of any known raido buttons. You could also compare the lParam to the HWND of the radio controls.

Maybe something like this:

if(LOWORD(wParam) == IDC_MYRADIOBTN)
      // We know this is a radio button

Or for the HWND attempt:

if((HWND)lParam == m_btnMyRadio.GetSafeHwnd())
     // Again we know this is a radio button


Also another problem is you might want to cast your GetDlgItem as a CButton (if the HIWORD(wParam) is BN_CLICKED). So like this:

          CButton *wnd = (CButton*)GetDlgItem(LOWORD(wParam));

Hope this will help,
Brandon
0
 

Author Comment

by:ManAtNext
ID: 17852081
Thanks for the response. I can't use it though as I'm needing this for a base class that needs to work on all radio buttons.

As it turns out what I needed to do was check for BS_AUTORADIOBUTTON. Do'h!
0
 
LVL 1

Accepted Solution

by:
kodiakbear earned 0 total points
ID: 17877288
Closed, 300 points refunded.
kb
Experts Exchange Moderator
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

829 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