Discussion:
CButton::GetButtonStyle() - how to interpret return value
(too old to reply)
Philipp Huber
2003-11-10 10:39:33 UTC
Permalink
hi!

is it possible that the function GetButtonStyle() returns one single style
value?

where can i get information when to use a mask and when to use the plain
value?
how about other controls/windows?

actually i am a little bit confused about this...

thanks, philipp
Jeff Partch [MVP]
2003-11-10 12:41:36 UTC
Permalink
Post by Philipp Huber
hi!
is it possible that the function GetButtonStyle() returns one single style
value?
I'm not sure what you're asking, but GetButtonStyle returns the LOBYTE of
the GetWindowLong/GWL_STYLE value. This should be any of the values from
BS_PUSHBUTTON through BS_BITMAP. Since these button styles (with the
exception of BS_LEFTTEXT it would appear) are not combinable bit flags but
rather exclusive and consecutive integers, I think you should consider it as
a single style value indicating the button's type.
Post by Philipp Huber
where can i get information when to use a mask and when to use the plain
value?
What mask do you have in mind? The SDK header #defines the BS_TYPEMASK value
that masks off all but the lower 4 bits of the style, which would seem to
mask out BS_LEFTTEXT, BS_ICON and BS_BITMAP from the value returned by
GetButtonStyle.
Post by Philipp Huber
how about other controls/windows?
I don't think you should use GetButtonStyle for controls/windows other than
those of the BUTTON WNDCLASS. The OS uses the upper 16bits of the GWL_STYLE
for general window styles and the lower 16bits are free for the WNDCLASS
implementation to define.
Post by Philipp Huber
actually i am a little bit confused about this...
Hope I've helped, but don't hesitate to say otherwise.
--
Jeff Partch [VC++ MVP]
SunFire
2003-11-10 12:46:31 UTC
Permalink
Post by Philipp Huber
hi!
is it possible that the function GetButtonStyle() returns one single style
value?
where can i get information when to use a mask and when to use the plain
value?
how about other controls/windows?
actually i am a little bit confused about this...
you can use following instruction:
if (GetButtonStyle() & BS_CHECKED)
{
//do something
}

Regards, Robert
Jeff Partch [MVP]
2003-11-10 13:08:50 UTC
Permalink
Post by SunFire
Post by Philipp Huber
hi!
is it possible that the function GetButtonStyle() returns one single style
value?
where can i get information when to use a mask and when to use the plain
value?
how about other controls/windows?
actually i am a little bit confused about this...
if (GetButtonStyle() & BS_CHECKED)
{
//do something
}
BS_CHECKED isn't an appropriate value. Assuming you meant BS_CHECKBOX, it's
a little more complicated than that as the simple & operation will match
more than one button style. Rather, I think you need to do something like...

if (BS_CHECKBOX == (GetButtonStyle() & BS_TYPEMASK))
{
// It's a regular checkbox
}

...but heck, even that may not be enough. :)
--
Jeff Partch [VC++ MVP]
SunFire
2003-11-10 14:57:52 UTC
Permalink
Post by Jeff Partch [MVP]
Post by SunFire
Post by Philipp Huber
hi!
is it possible that the function GetButtonStyle() returns one single
style
Post by SunFire
Post by Philipp Huber
value?
where can i get information when to use a mask and when to use the plain
value?
how about other controls/windows?
actually i am a little bit confused about this...
if (GetButtonStyle() & BS_CHECKED)
{
//do something
}
BS_CHECKED isn't an appropriate value. Assuming you meant BS_CHECKBOX, it's
a little more complicated than that as the simple & operation will match
more than one button style. Rather, I think you need to do something like...
if (BS_CHECKBOX == (GetButtonStyle() & BS_TYPEMASK))
{
// It's a regular checkbox
}
...but heck, even that may not be enough. :)
you're absolutelly right.
Regards, Robert

Philipp Huber
2003-11-10 14:27:41 UTC
Permalink
Post by Jeff Partch [MVP]
Since these button styles (with the
exception of BS_LEFTTEXT it would appear) are not combinable bit flags but
rather exclusive and consecutive integers, I think you should consider it
as
Post by Jeff Partch [MVP]
a single style value indicating the button's type
actually this was what i wanted to know - i am sorry for my unclear
english...
Post by Jeff Partch [MVP]
if (BS_CHECKBOX == (GetButtonStyle() & BS_TYPEMASK))
{
// It's a regular checkbox
}
if i have understood your explanations correctly GetButtonStyle() should
return one exclusive value out of the BS_styles - so what about this
"(GetButtonStyle() & BS_TYPEMASK)"?

thanks, philipp
Jeff Partch [MVP]
2003-11-10 14:50:58 UTC
Permalink
Post by Philipp Huber
Post by Jeff Partch [MVP]
Since these button styles (with the
exception of BS_LEFTTEXT it would appear) are not combinable bit flags but
rather exclusive and consecutive integers, I think you should consider it
as
Post by Jeff Partch [MVP]
a single style value indicating the button's type
actually this was what i wanted to know - i am sorry for my unclear
english...
Post by Jeff Partch [MVP]
if (BS_CHECKBOX == (GetButtonStyle() & BS_TYPEMASK))
{
// It's a regular checkbox
}
if i have understood your explanations correctly GetButtonStyle() should
return one exclusive value out of the BS_styles - so what about this
"(GetButtonStyle() & BS_TYPEMASK)"?
It may not be exactly right in general, but it was an attempt to mask out
the BS_LEFTTEXT bit which is seemingly combinable with the checkbox and
radio button style types, but it will also mask off the BS_ICON and
BS_BITMAP types. In general, the BS_* styles in the lower 8 bits are not
combinable (except that by combining them you can come up with some other
button type). For example: (BS_AUTOCHECKBOX | BS_RADIOBUTTON) is the same
value as BS_GROUPBOX.
--
Jeff Partch [VC++ MVP]
Loading...