Owner-drawn button with BS_AUTORADIOBUTTON style

1.2k views Asked by At

How do I get the checked/unchecked state of BS_AUTORADIOBUTTON? My code currently doesn't work.

void CPngButton::DrawItem( LPDRAWITEMSTRUCT lpDIS )
{
    ASSERT(lpDIS != NULL);

    UINT state = lpDIS->itemState;
    if (state & ODS_CHECKED)
    {
    // do stuff
    }
}

I've also tried

if (BST_CHECKED == SendMessage(BM_GETCHECK))

but this doesn't work either.

2

There are 2 answers

1
Erik On BEST ANSWER

ODS_CHECKED only applies to menus. BM_GETCHECK and BM_GETSTATE can both provide the checked state:

if (Button_GetState(lpDIS->hwndItem) & BST_CHECKED)
0
Cody Gray - on strike On

According to the documentation, the ODS_CHECKED flag is only applicable to menu items:

ODS_CHECKED   This bit is set if the menu item is to be checked. This bit is used only in a menu.

Instead, to determine the checked state of a button, you should call the CButton::GetCheck function. It will return one of the following values:

BST_UNCHECKED           The button is unchecked

BST_CHECKED               The button is checked

BST_INDETERMINATE   Button state is indeterminate (only if BS_3STATE or BS_AUTO3STATE set).

For example:

CButton myBtn;
if (myBtn.GetCheck() = BST_CHECKED)
{
    // Drawing code here...
}