Solved

Is it a radio button? In OnCommand

Posted on 2006-11-01
4
301 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

786 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