Jump to content

Styles names and Window Info tools


Recommended Posts

Hi everybody :)
My goal is to be able to display Control styles names in Yashied's control viewer (which is now maintained by @argumentum) but I'm having some issues and questions that require your help, thanks in advance.

In the 1st pic below, we have the official AutoIt Window Info tool on the left, my Gui in the middle, Yashied's Control Viewer on the right.

81480369_10-2AutoItinfotools.png.e43bfa2c995854cf65a992b8e61778ea.png

The studied control is a Radio button control, whose class is "Button" (please note that Checkbox controls and  Push Buttons controls got the same "Button" class)

To retrieve and display correctly the style name "BS_AUTORADIOBUTTON" in Yashied's tool, I had to sort (descending) all the Button control styles, as shown below :

Global Const $Style_Button[20][2] = _ ; sorted descending (bc not all elements are multiples)
   [[0x8000, 'BS_FLAT'], _
    [0x4000, 'BS_NOTIFY'], _
    [0x2000, 'BS_MULTILINE'], _
    [0x1000, 'BS_PUSHLIKE'], _
    [0x0C00, 'BS_VCENTER'], _
    [0x0800, 'BS_BOTTOM'], _
    [0x0400, 'BS_TOP'], _
    [0x0300, 'BS_CENTER'], _
    [0x0200, 'BS_RIGHT'], _
    [0x0100, 'BS_LEFT'], _
    [0x0080, 'BS_BITMAP'], _
    [0x0040, 'BS_ICON'], _
    [0x0020, 'BS_RIGHTBUTTON'], _
    [0x0009, 'BS_AUTORADIOBUTTON'] , _
    [0x0007, 'BS_GROUPBOX'], _
    [0x0006, 'BS_AUTO3STATE'], _
    [0x0005, 'BS_3STATE'], _
    [0x0003, 'BS_AUTOCHECKBOX'], _
    [0x0002, 'BS_CHECKBOX'], _
    [0x0001, 'BS_DEFPUSHBUTTON']]

If that Array was left unsorted, for example something like this...
 

...
    [0x0005, 'BS_3STATE'], _
    [0x0003, 'BS_AUTOCHECKBOX'], _
    [0x0002, 'BS_CHECKBOX'], _
    [0x0001, 'BS_DEFPUSHBUTTON'], _
    [0x0009, 'BS_AUTORADIOBUTTON']]

...then the result would have been wrongly displayed :

631239283_11-Yashiedtool.png.bc233456f9c35e7de140593474ea98fa.png

This is because the Button Styles array got values which are not all multiples (i.e "multiples" mean 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100 etc...) and the Bitwise operations would have been done differently, in a wrong way.

The problem wouldn't happen, for example, with an unsorted "Edit" Class (used for Edit & Input controls), where all elements got value that are multiples, as shown below :

Global Const $Style_Edit[13][2] = _
   [[0x0080, 'ES_AUTOHSCROLL'], _
    [0x0040, 'ES_AUTOVSCROLL'], _
    [0x0001, 'ES_CENTER'], _
    [0x0010, 'ES_LOWERCASE'], _
    [0x0100, 'ES_NOHIDESEL'], _
    [0x2000, 'ES_NUMBER'], _
    [0x0400, 'ES_OEMCONVERT'], _
    [0x0004, 'ES_MULTILINE'], _
    [0x0020, 'ES_PASSWORD'], _
    [0x0800, 'ES_READONLY'], _
    [0x0002, 'ES_RIGHT'], _
    [0x0008, 'ES_UPPERCASE'], _
    [0x1000, 'ES_WANTRETURN']]

For the record, style names extraction is done like shown below, where $Data is an Array of the styles corresponding to the control class (as the "Button" or "Edit" arrays shown above) and $iStyle the value of the several styles of the control :

$Text = ""
For $i = 0 To UBound($Data) - 1
    If BitAND($iStyle, $Data[$i][0]) = $Data[$i][0] Then
        $iStyle = BitAND($iStyle, BitNOT($Data[$i][0]))
        ; $iStyle = BitXOR($iStyle, $Data[$i][0])
        $Text = $Data[$i][1] & ', ' & $Text
    EndIf
Next

By the way, in Yashied's original code, I notice something that could cause issues, because he scripted it like this :

If BitAND($iStyle, $Data[$i][0]) = Then

Which gave me (sometimes) different results when a style is unset, depending on the way it is unset :

$iStyle = BitAND($iStyle, BitNOT($Data[$i][0]))
$iStyle = BitXOR($iStyle, $Data[$i][0])

So it seems to work correctly now that I changed it to :

If BitAND($iStyle, $Data[$i][0]) = $Data[$i][0] Then

My 2 questions are :
1) Is there any way to retrieve more information than a class named "Button", so I could know exactly what is the studied control (a push button ? a radio button ? a check control button ?)

2) When Array's elements are not all multiples (case of the $Style_Button array), is it the correct way to retrieve Styles names, i.e. sort the array descending then check each element from the 1st element (highest value) to the last (lowest value) ?
Because if it's the correct way to do it, then I'll have to sort (descending) all the other Arrays whose elements are not all multiples.

I don't know how Windows manage this internally, maybe it uses a different way to retrieve the correct styles of any control belonging to the "Button" class.

Thanks for your advices.

Link to comment
Share on other sites

1- UIAutomation can provide you this information :

image.png.b67b2601abba66017c60e9992fabf8af.png

2- I would not remove the bits from the total style.  When you set a style you use BitOr(blah, blah, blah).  Lets say you are setting 0110 (0x06) and 1100 (0x0C), so you get 1110 (0x0E) total style.  If you remove 1100 style, you will lose 0110 style.  Removing bits on single bit style does not matter but on multi-bits it does.

Edited by Nine
Link to comment
Share on other sites

5 hours ago, Nine said:

Removing bits on single bit style does not matter but on multi-bits it does.

If I understand you correctly, does the following example illustrate what you mean by "single bit style" ?

================================
12345678901234567890123456789012 (32 columns)
================================
                               1 (0x1) => style 1
                              10 (0x2) => style 2
                             100 (0x4) => style 3
                            1000 (0x8) => style 4
           ....                   ... 

   10000000000000000000000000000 (0x10000000) => style 29
  100000000000000000000000000000 (0x20000000) => style 30
 1000000000000000000000000000000 (0x40000000) => style 31
10000000000000000000000000000000 (0x80000000) => style 32

Ideally, each control class should have a maximum of 32 styles and each style should contain a single bit = 1, whose position should be unique and never be placed at the same "column" than another style for this class.

When this miracle happens (in the diagram above, or in the $Style_Edit array shown in my 1st post) then you can BitOr and BitXOR any of these 32 styles without problem, because you'll never find 2 bits = 1 at the same position and results will always be correct.

5 hours ago, Nine said:

Lets say you are setting 0110 (0x06) and 1100 (0x0C), so you get 1110 (0x0E) total style.

The question here is : did we just set 2 valid styles or not ?
And if both styles are valid, didn't we make a mistake by setting both of them ?
To explain this better, here is a part of the sorted array $Style_Button copied from the 1st post :

...
[0x0C00, 'BS_VCENTER'], _
[0x0800, 'BS_BOTTOM'], _
...

; 0xC00 => 110000000000
; 0x800 => 100000000000

Two "1" bits are at the same position, which makes us frown... but how these 2 styles could ever have been BitOr'ed, when one of them means "Vertically centers text in the button rectangle" and the other one means "Places the text at the bottom of the button rectangle" . Isn't it the reason why MS choosed this 0xC00 'non-standard' style number, because nothing bad will happen ?

Now, concerning the lowest part of the $Style_Button array (sorted descending) :

[0x0009, 'BS_AUTORADIOBUTTON'] , _
[0x0007, 'BS_GROUPBOX'], _
[0x0006, 'BS_AUTO3STATE'], _
[0x0005, 'BS_3STATE'], _
[0x0003, 'BS_AUTOCHECKBOX'], _
[0x0002, 'BS_CHECKBOX'], _
[0x0001, 'BS_DEFPUSHBUTTON']]

Aren't the values exclude themselves mutually ?
I mean, when you check each value of the array, starting from the highest values,  if "0x0009" is found, then it's a radio button and none of the rest (below "0x0009") should/could have been BitOr'ed
If "0x0007" is found, then it's a group box and none of the rest etc...

Don't ask me about "0x0001" BS_DEFPUSHBUTTON because this one drives me nuts !
Try to create in Koda an empty form with a couple of buttons, one of them having a $BS_DEFPUSHBUTTON style (0x0001) . While in Koda, you see at the bottom of the Style tab that 0x0001 has been correctly added for 1 button only.

But when you run the resulting code...

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 413, 298, 302, 218)
$Button1 = GUICtrlCreateButton("Button1", 56, 40, 73, 33)
$Button2 = GUICtrlCreateButton("Button2", 144, 40, 65, 33, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

...and launch the "AutoIt Window Info" tool (or Yashied's tool) then this 0001 has vanished for the control style total value !

Anyway, as the sorted (descending) array seems to work fine for the Button class (I tested it on checkbox controls too, it displayed the correct BS_AUTOCHECKBOX style name in Yashied's tool), then I'll try this "descending" way in the concerned class arrays (gladly not all of them are concerned) and check the results for each control class.

@Nine I hope no offense was taken in case something I wrote seemed a bit harsh, it's just my way of writing when I would like to understand more than I do :)

Link to comment
Share on other sites

...based on @Nine's bitwise observation, I changed the _GetStyleString() mod.  .
That way the sorting is one thing, and the removal of bits in $sStyle is not affected ... hmmm, no clue.
Anyway, I did the change in the code, but now that I think of if I may have messed it up 
:huh2:
Sorry, carry on :) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

No offense taken.  But I prefer having more styles than missing some. Removing is still a bad idea in my opinion (it is just a ancestry habit).

You can relate to what is has been in use.  You cannot if you remove those bits.

But basically, we need to know if style are additive or mutually exclusive. 

Edited by Nine
Link to comment
Share on other sites

@argumentum: you'll notice below that some styles are missing in AutoIt help file (topic GUI Control Styles) but some of them can be found in AutoIt includes. Here is an example :

ComboBox.png.58dda79a5d82e1edfed1bcf9a7f3ebbc.png

What means "0x0200" in the ComboBox class ?

It means "$CBS_HASSTRINGS = 0x200 ; Specifies that an owner-drawn combo box contains items consisting of strings"

We can find this style explained in file "ComboConstants.au3" but not in AutoIt help file, which means that the include file we prepared for Yashied's script needs to be updated (I'm slowly working on it now, due to back health problems, X-rays on tuesday !)

What's interesting now is what happens if we study the Edit control included in the preceding ComboBox :

1185774271_EditinComboBox.png.ca6d437ece2a4540746da6d1598ad3b0.png

What means "0x0200" in the Edit class ??
I don't have a name for it, but if you look at the sorted Edit style array we worked on :

Global Const $Style_Edit[13][2] = _
   [[0x2000, 'ES_NUMBER'], _
    [0x1000, 'ES_WANTRETURN'], _
    [0x0800, 'ES_READONLY'], _
    [0x0400, 'ES_OEMCONVERT'], _
    [0x0100, 'ES_NOHIDESEL'], _
    [0x0080, 'ES_AUTOHSCROLL'], _
    [0x0040, 'ES_AUTOVSCROLL'], _
    [0x0020, 'ES_PASSWORD'], _
    [0x0010, 'ES_LOWERCASE'], _
    [0x0008, 'ES_UPPERCASE'], _
    [0x0004, 'ES_MULTILINE'], _
    [0x0002, 'ES_RIGHT'], _
    [0x0001, 'ES_CENTER']]

13 values found which are (how I name them) "multiples" (1-2-4-8-10-20-40-80-100- ?? -400-800-1000-2000)
The only "missing" one is 0x200, incredible but true !

I didn't find on the Web any information concerning an Edit style value of 0x200. If anyone got more precisions about this, please share them here, thanks.

Note: 1 min ago, I thought of "creating" an Edit style, value 0x0200 named "ES_HASSTRINGS" (based on $CBS_HASSTRINGS name). As I'm curious, I just googled on "ES_HASSTRINGS" in case of... and found 1 link, (some korean words on the web page), where we can read :

CBS_HASSTRINGS = ES_HASSTRINGS : Has strings

Here is the link (Mods, if you think the link should be removed, please do not hesitate) :
https://petra.tistory.com/939

Link to comment
Share on other sites

1 hour ago, pixelsearch said:

... I thought of "creating" an Edit style, value 0x0200 named "ES_HASSTRINGS" (based on $CBS_HASSTRINGS name) ...

I never needed to brake down the magic numbers into its components by name. It is a welcomed addition to have for sure but, something to get a PhD from, I mean, ..is not gonna be easy researching to the point of excellence. So get better, and finish your job  ;)

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

These "magic" values are all defined in the windows SDK and if they are not there they are not used / not exist windows.h or winuser.h 

Combobox styles are independent defined from edit control styles so defining ES_HASSTRINGS is useless for edit box style.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...