Solved

Is it a radio button? In OnCommand

Posted on 2006-11-01
4
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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