Determining button type from its style

My question is,
I have a Radio, a Check and a Push button on a dialog. the class for all 3 is button. By using the style I want to determine which one is the radio, the check and the push button.
However when comparing (anding) the style of each button with
BS_PUSHBUTTON
BS_DEFPUSHBUTTON
BS_CHECKBOX
BS_AUTOCHECKBOX
BS_RADIOBUTTON
BS_3STATE
BS_AUTO3STATE
BS_GROUPBOX
BS_USERBUTTON
BS_AUTORADIOBUTTON  
I'm getting a combination of the above that doesn't seem correct.
For instance the radio button returned types of
BS_DEFPUSHBUTTON
BS_AUTOCHECKBOX
BS_3STATE
BS_GROUPBOX
BS_USERBUTTON
BS_AUTORADIOBUTTON

Can anyone explain why this is the case and perhaps a better way of determining what type of button it is
PaulBlackAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
There must be something wrong with your code. Use Spy++ to check the styles to see if they are the same as what you have found out.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodCommented:
The problem is that the styles are'n mutually exclusive.  i.e the styles aren't indicated by distinct bits  

continues.
0
nietodCommented:
Sorry about the delay, I had a phone call.

The button styles are just a mess.  Here is a copy from windows.h

#define BS_PUSHBUTTON       0x00000000L
#define BS_DEFPUSHBUTTON    0x00000001L
#define BS_CHECKBOX         0x00000002L
#define BS_AUTOCHECKBOX     0x00000003L
#define BS_RADIOBUTTON      0x00000004L
#define BS_3STATE           0x00000005L
#define BS_AUTO3STATE       0x00000006L
#define BS_GROUPBOX         0x00000007L
#define BS_USERBUTTON       0x00000008L
#define BS_AUTORADIOBUTTON  0x00000009L
#define BS_OWNERDRAW        0x0000000BL

Ignoring the OWNERDFRAW, style, all these styles use only the low nible and none of the other styles use the low nible.  So I think the best bet is to mask off the low nible (AND with 0fh). Then compare the results to each of these styles.
0
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

nietodCommented:
Ignore what I said about the OWNERDRAW style.  I thought it was a style that could be added to any of the others.  It isn't.  It is a distinct style, just lke the others.  So just mask of the low nibble and compare.
0
PaulBlackAuthor Commented:
What do you mean by
"So just mask of the low nibble and compare."

the code I'm using is

if (uStyle & BS_PUSHBUTTON)
//Its a bs_pushbutton
//do stuff here
else if (uStyle & BS_RADIOBUTTON)
//Its a bs_radiobutton
//do stuff here
else if (uStyle & BS_CHECKBOX)
//Its a bs_checkbox
//do stuff here
else if (uStyle & BS_3STATE)
//Its a bs_3state
//do stuff here
0
nietodCommented:
That is wrong.  Look at the numbers that these styles represent.  For example,BS_DEFPUSHBUTTON is 1 and BS_AUTOCHECKBOX is 3.  That means that both of these have the 1's but set.  So if a styles is BS_AUTOCHECKBOX it will appear to be BS_DEFPUSBUTON to.  (The reverse is not true.)  IOn fact half of them will appear to be BS_DEFPUSHBUTTON.  

You can use ANDing only when the values you are testing for are indicated by seperate bits being set.  i.e each seperate value you are testing for is indicated by a seperate bit.  That is not the case here.  Here they have numbered the values, using the low nibble (4 bits) to store a binary number.  Because of this there are several values that have bits some set in common.

continues
0
nietodCommented:
Given a style mask of the low nibble, like
int Typ = uStyle & 0x0F;

Then compare this value to the styles (== not &), like

if (uStyle == BS_PUSHBUTTON)
   //Its a bs_pushbutton
   //do stuff here
else if (uStyle == BS_RADIOBUTTON)
0
PaulBlackAuthor Commented:
Thanks a million, now working fine
Paul
0
PaulBlackAuthor Commented:
Those points were meant to go to nietod !
not sure how to change this
:<(
Paul
0
nietodCommented:
In the future, reject the incorrect answer, then either ask the other expert to answer, and then grade his/her answer or select one of the "accept comment as answer" links on a comment posted by the expert.
0
chensuCommented:
Sorry, nietod.
0
nietodCommented:
Its not your fault...Its PaulBlack's fault.  Just kidding.  :-)

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.