Solved

Is it a radio button? In OnCommand

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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.

730 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