Question

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.

Was it helpful?

Solution

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

if (Button_GetState(lpDIS->hwndItem) & BST_CHECKED)

OTHER TIPS

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...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top