Page 1 of 1
Distinguishing between Checkboxes/Radios/GroupBoxes..HELP!
Posted: Mon Jun 07, 2004 12:19 am
by PolyVector
I'm having a serious hold up with my skin engine due to something very... simple...
I can't seem to distinguish between Checkboxes, RadioButtons, GroupBoxes and standard Buttons....
Please try out this code demonstrating my problem, and see if you can figure out what's wrong:
Code: Select all
OpenWindow(0,0,0,150,100,#PB_Window_SystemMenu,"Button Class Problems")
CreateGadgetList(WindowID())
ButtonGadget(0,0,0,150,20,"Button")
Frame3DGadget(1,0,25,150,20,"GroupBox")
CheckBoxGadget(2,0,50,150,20,"CheckBox")
OptionGadget(3,0,75,150,20,"RadioButton")
For GadgetNumber=0 To 3
handle=GadgetID(GadgetNumber)
ClassName$=Space(256)
GetClassName_(handle,@ClassName$,256)
Text$=Space(256)
GetWindowText_(handle,@Text$,256)
Style=GetWindowLong_(handle,#GWL_Style)
Select ClassName$
Case "Button"
If Style&#BS_CHECKBOX; Or Style&#BS_AUTOCHECKBOX
Debug "'"+Text$+"' is a Checkbox"
ElseIf Style&#BS_AUTORADIOBUTTON
Debug "'"+Text$+"' is a RadioButton"
ElseIf Style&#BS_GROUPBOX
Debug "'"+Text$+"' is a GroupBox"
Else
Debug "'"+Text$+"' is a Button"
EndIf
EndSelect
Next
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
For some reason it thinks the GroupBox is a CheckBox... And if I change the code in any way it gets even worse... Try for yourself...
Posted: Mon Jun 07, 2004 12:54 pm
by Sparkie
Not sure why your Style check doesn't work properly, but adding a check for #WS_TABSTOP seems to work.
Code: Select all
OpenWindow(0,0,0,150,100,#PB_Window_SystemMenu,"Button Class Problems")
CreateGadgetList(WindowID())
ButtonGadget(0,0,0,150,20,"Button")
Frame3DGadget(1,0,25,150,20,"GroupBox")
CheckBoxGadget(2,0,50,150,20,"CheckBox")
OptionGadget(3,0,75,150,20,"RadioButton")
For GadgetNumber=0 To 3
handle=GadgetID(GadgetNumber)
ClassName$=Space(256)
GetClassName_(handle,@ClassName$,256)
Text$=Space(256)
GetWindowText_(handle,@Text$,256)
Style=GetWindowLong_(handle,#GWL_Style)
Select ClassName$
Case "Button"
If Style&#BS_CHECKBOX And Style&#WS_TABSTOP
Debug "'"+Text$+"' is a Checkbox"
ElseIf Style&#BS_AUTORADIOBUTTON And Style&#WS_TABSTOP
Debug "'"+Text$+"' is a RadioButton"
ElseIf Style&#BS_GROUPBOX And Style~#WS_TABSTOP
Debug "'"+Text$+"' is a GroupBox"
Else
Debug "'"+Text$+"' is a Button"
EndIf
EndSelect
Next
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
Posted: Tue Jun 08, 2004 6:09 am
by PolyVector
Odd, that does work, but I don't think it's reliable... #WS_TabStop shouldn't really have to do with what kind of 'Button' it is... I think it's coincidental...
Anybody else have a clue why my code doesn't work?... I've read up on msdn and can't figure it out

Posted: Tue Jun 08, 2004 7:49 am
by Dare2
I think Sparkie has it.
msdn wrote:style
Control styles. This value can be a combination of the button class style BS_GROUPBOX and the WS_TABSTOP and WS_DISABLED styles.
If you do not specify a style, the default style is BS_GROUPBOX.
http://msdn.microsoft.com/library/en-us ... ontrol.asp
Posted: Tue Jun 08, 2004 9:58 am
by PolyVector
Wow thanks guys... Maybe you're right Sparkie, I would have never guessed that!
I love this forum

Posted: Tue Jun 08, 2004 10:25 am
by PolyVector
Actually.... after further testing... that doesn't work... ws_tabstop doesn't seem to be the answer

Posted: Tue Jun 08, 2004 10:36 am
by Dare2
Actually I had just come to the same conclusion. Something is not quite right here.
Numbers are Style return, the constant value, and name
$50020007 - 7 - BS_GROUPBOX
$50030003 - 2 - BS_CHECKBOX
$50030009 - 9 - BS_AUTORADIOBUTTON
It appears to returning BS_AUTOCHECKBOX (3)
Posted: Tue Jun 08, 2004 10:42 am
by PolyVector
no matter what i do, i can't figure this one out... I've tried checking for all combinations of bs_checkbox, bs_autocheckbox...bs_radiobutton, bs_autoradiobutton......
it seems to think bs_autoradiobutton=bs_autocheckbox.... and there's some other oddities....
I really hope I'm doing something wrong
Posted: Tue Jun 08, 2004 10:48 am
by Dare2
Do this:
Code: Select all
If Style&#BS_CHECKBOX
Debug "'"+Text$+"' is a Checkbox"
EndIf
If Style&#BS_AUTORADIOBUTTON
Debug "'"+Text$+"' is a RadioButton"
EndIf
If Style&#BS_GROUPBOX
Debug "'"+Text$+"' is a GroupBox"
EndIf
Everything is everything.
Then this:
Code: Select all
Style=Style & $000000FF
Select ClassName$
Case "Button"
If Style = #BS_CHECKBOX Or Style=#BS_AUTOCHECKBOX
Debug "'"+Text$+"' is a Checkbox"
EndIf
If Style = #BS_AUTORADIOBUTTON
Debug "'"+Text$+"' is a RadioButton"
EndIf
If Style = #BS_GROUPBOX
Debug "'"+Text$+"' is a GroupBox"
EndIf
EndSelect
Everything is sweet.
Posted: Tue Jun 08, 2004 11:08 am
by PolyVector
There seems to be some problem with the & Operator... Now I don't know much about Signed/Unsigned variables but maybe that could that affect the output?
Tell me if I'm way off here but.... does this make sense to you?
Code: Select all
Style=#BS_GROUPBOX
If Style&#BS_CHECKBOX
MessageRequester("Message from PolyVector","Hrmmmm...")
EndIf
Style=#BS_AUTOCHECKBOX
If Style&#BS_AUTORADIOBUTTON
MessageRequester("Message from PolyVector","Am I missing something here?")
EndIf
Style=#BS_GROUPBOX
If Style&#BS_AUTORADIOBUTTON
MessageRequester("Message from PolyVector","*Cries*")
EndIf
Please, someone tell me I'm using the & Operator completely wrong!
Edit: and I am

Posted: Tue Jun 08, 2004 11:16 am
by PolyVector
Your code works, but I need this detection to work globally... any changes to the styles, such as #BS_RIGHTBUTTON would result in no detection using that method....
Posted: Tue Jun 08, 2004 11:29 am
by Dare2
The AND will always return a non-zero on the values above as both the style value and the constant have bit zero set to 1.
9=1001, 7=0111, 3=0011
I think any bit (AND, OR, XOR) manipulation will fail because the bits are shared and thus far I can't find any patterning of bits.
Not sure what your app actually does, but is there any way you can trap and store style changes into variable(s) and compare against the variable(s)?
EDITED
Anyhow, at this point my 2 brain cells are exhausted. Another beer or two should fix that. (Or reduce them to 1 solo brain cell, which at least has the advantage of not seeing any other point of view at all!)
Success to you.
Posted: Tue Jun 08, 2004 11:39 am
by PolyVector
Thanks Dare2,
You've been a lot of help.... This is for a skinning library I'm making (that works great btw, it just has trouble detecting those damned Button styles...haha...)
I'm just gunna fart around with this a while longer....I think I'll make it to 5am
Thanks again!
Posted: Tue Jun 08, 2004 12:25 pm
by PolyVector
Solution?:
Code: Select all
OpenWindow(0,0,0,150,100,#PB_Window_SystemMenu,"Button Class Problems")
CreateGadgetList(WindowID())
ButtonGadget(0,0,0,150,20,"Button")
Frame3DGadget(1,0,25,150,20,"GroupBox")
CheckBoxGadget(2,0,50,150,20,"CheckBox")
OptionGadget(3,0,75,150,20,"RadioButton")
For GadgetNumber=0 To 3
handle=GadgetID(GadgetNumber)
ClassName$=Space(256)
GetClassName_(handle,@ClassName$,256)
Text$=Space(256)
GetWindowText_(handle,@Text$,256)
Style=GetWindowLong_(handle,#GWL_Style)
Select ClassName$
Case "Button"
If Style&#BS_GROUPBOX=#BS_GROUPBOX
Debug "'"+Text$+"' is a GroupBox"
ElseIf Style&#BS_CHECKBOX=#BS_CHECKBOX Or Style&#BS_AUTOCHECKBOX=#BS_AUTOCHECKBOX Or Style&#BS_3STATE=#BS_3STATE Or Style&#BS_AUTO3STATE=#BS_AUTO3STATE; Or Style&#BS_AUTOCHECKBOX
Debug "'"+Text$+"' is a Checkbox"
ElseIf Style&#BS_RADIOBUTTON=#BS_RADIOBUTTON Or Style&#BS_AUTORADIOBUTTON=#BS_AUTORADIOBUTTON
Debug "'"+Text$+"' is a RadioButton"
ElseIf Style&#BS_PUSHBUTTON=#BS_PUSHBUTTON Or Style&#BS_DEFPUSHBUTTON=#BS_DEFPUSHBUTTON
Debug "'"+Text$+"' is a Button"
EndIf
EndSelect
Next
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
This seems to always work

Posted: Tue Jun 08, 2004 12:43 pm
by Dare2
Grats. Nifty (and too easy - now that you show how).
Success with the skinning.
