Solved

Is it a radio button? In OnCommand

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

Highfive Gives IT Their Time Back

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!

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 …
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.
This video discusses moving either the default database or any database to a new volume.

744 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

12 Experts available now in Live!

Get 1:1 Help Now