Reputation: 79665
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.
Upvotes: 3
Views: 1309
Reputation: 244913
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 ifBS_3STATE
orBS_AUTO3STATE
set).
For example:
CButton myBtn;
if (myBtn.GetCheck() = BST_CHECKED)
{
// Drawing code here...
}
Upvotes: 1
Reputation: 91310
ODS_CHECKED only applies to menus. BM_GETCHECK and BM_GETSTATE can both provide the checked state:
if (Button_GetState(lpDIS->hwndItem) & BST_CHECKED)
Upvotes: 4