Distinguishing between Checkboxes/Radios/GroupBoxes..HELP!

Everything else that doesn't fall into one of the other PB categories.
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Distinguishing between Checkboxes/Radios/GroupBoxes..HELP!

Post by PolyVector »

I'm having a serious hold up with my skin engine due to something very... simple... :oops:
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...
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post 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 :cry:
Last edited by PolyVector on Tue Jun 08, 2004 10:25 am, edited 1 time in total.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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
@}--`--,-- A rose by any other name ..
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

Wow thanks guys... Maybe you're right Sparkie, I would have never guessed that!
I love this forum :D
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

Actually.... after further testing... that doesn't work... ws_tabstop doesn't seem to be the answer :(
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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)
@}--`--,-- A rose by any other name ..
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post 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
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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.
@}--`--,-- A rose by any other name ..
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post 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 :)
Last edited by PolyVector on Tue Jun 08, 2004 11:40 am, edited 1 time in total.
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post 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....
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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.
@}--`--,-- A rose by any other name ..
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post 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!
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post 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 :)
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Grats. Nifty (and too easy - now that you show how). :D

Success with the skinning. :)
@}--`--,-- A rose by any other name ..
Post Reply