Sign in to follow this  
Followers 0
Jon

Group controls

7 posts in this topic

I'm fixing the way that controls are grouped (WS_GROUP). (Not quite the same as a "group" control)

I'm adding a new command that will indicate a new group has started but don't know what to call it:

GuiGroup()

GuiGroupStart()

GuiSetGroup()

?

At the moment I'm using GuiSetGroup and it looks like this (this example would have 2 distinct groups of radio controls - ignore the dimensions)

GUISetGroup()
$radio_1 = GUISetControl("radio", "Radio 1", 50, 120, 70, 20)
$radio_2 = GUISetControl("radio", "Radio 2", 50, 150, 60, 20)
$radio_3 = GUISetControl("radio", "Radio 3", 50, 180, 60, 20)
GUISetGroup()
$radio_4 = GUISetControl("radio", "Radio 1", 200, 120, 70, 20)
$radio_5 = GUISetControl("radio", "Radio 2", 200, 150, 60, 20)
$radio_6 = GUISetControl("radio", "Radio 3", 200, 180, 60, 20)
GUISetGroup()

It works as long as the SetGroup function is called between required groups of controls.

Devs:

The current implementation incorrectly uses the WS_GROUP style on most controls and you also have to define radio buttons in a certain way for tabbing to work as a standard dialog

The WS_GROUP Style

By default, the system moves the input focus to the next or previous control whenever the user presses a direction key. As long as the current control with the input focus does not process these keys and the next or previous control is not a static control, the system continues to move the input focus through all controls in the dialog box as the user continues to press the direction keys.

An application can use the WS_GROUP style to modify this default behavior. The style marks the beginning of a group of controls. If a control in the group has the input focus when the user begins pressing direction keys, the focus remains in the group. In general, the first control in a group must have the WS_GROUP style and all other controls in the group must not have this style. All controls in the group must be contiguous—that is, they must have been created consecutively with no intervening controls.

Generally, the first control in the group combines the WS_GROUP and WS_TABSTOP styles so that the user can move from group to group by using the TAB key. If the group contains radio buttons, the application should apply the WS_TABSTOP style only to the first control in the group. The system automatically moves the style when the user moves between controls in the group. This ensures that the input focus will always be on the most recently selected control when the user moves to the group using the TAB key.

I just have some work to do on modifying BM_SETCHECK to work with radio controls (it subtly messes up focus/tabbing - Need to use CheckRadioButton() but that is not as simple as it sounds :D )

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Just two questions

  • as we can defined dynamycally a new control,

    will be possible to have the GuiSetGroup referencing a previous defined group :D

  • Does that suppress the GuiSetControl("group",...
Edited by jpm

Share this post


Link to post
Share on other sites

Just two questions

  • as we can defined dynamycally a new control,

    will be possible to have the GuiSetGroup referencing a previous defined group :huh2:

  • Does that suppress the GuiSetControl("group",...
No, because dialogs (in general, not only in AutoIt) work on sequential ID numbers and WS_GROUP styles for defining grouped controls, so if you add a new control at a later date it will have a much higher ID number and not be part of the same group.

A "group" control is actually nothing to do with WS_GROUP - it's just a box that is used as a visual clue for the user :D

I'm just about to upload it with a nice radio box example so you will be able to see what I mean (2 sets of seperate radio controls within a single "group" control)

Share this post


Link to post
Share on other sites

No, because dialogs (in general, not only in AutoIt) work on sequential ID numbers and WS_GROUP styles for defining grouped controls,  so if you add a new control at a later date it will have a much higher ID number and not be part of the same group.

A "group" control is actually nothing to do with WS_GROUP - it's just a box that is used as a visual clue for the user :)

I'm just about to upload it with a nice radio box example so you will be able to see what I mean (2 sets of seperate radio controls within a single "group" control)

I see before the download. :D:huh2:

Share this post


Link to post
Share on other sites

I don't understand why with the radio box inside a group control the tab is not working anymore.

I think if radiobox are inside a group control it should work too without adding a GuiSetGroup and tab by default control to control.

#include "GUIConstants.au3"
AutoItSetOption("TrayIconDebug", 1)
Opt("GuiNotifyMode",1)

GUICreate("My Test GUI",350,300,-1,-1,$WS_SIZEBOX+$WS_SYSMENU) ; will create a dialog box that when displayed is centered

GUICreateEx("notepad", 0xE0FFFF) ; wil,l run notepad if F1 is typed

GuiSetControl("label", "Label1",  10, 30, 50); first cell 50 width
AutoItSetOption("GUICoordMode", 2)
GuiSetControl("label", "Label2",  -1, 0); next line
GuiSetControl("label", "Label3",  0, 0); next line and next cell 
GuiSetControl("label", "Label4",  0, -1); next cell
GuiSetControl("combo","combo1",-150,0)
GuiSetControl("list","list1",0,-1, 50,75)

GuiSetControl("group","group1",0,-177,100)
AutoItSetOption("GUICoordMode", 0)
GuiSetControl("radio","radio1",8,16, 90, 20)
AutoItSetOption("GUICoordMode", 2)
GuiSetControl("radio","radio2",-1,0)

AutoItSetOption("GUICoordMode", 0)
GuiSetControl("checkbox","check1",0,75)
AutoItSetOption("GUICoordMode", 2)
GuiSetControl("checkbox","check2",-1,0)

AutoItSetOption("GUICoordMode", 1)

GuiSetControl("group","group2",220,0,100,75)
AutoItSetOption("GUICoordMode", 0)
GuiSetControl("radio","radio3",8,16, 90, 20)
AutoItSetOption("GUICoordMode", 2)
GuiSetControl("radio","radio4",-1,0)

GuiSetControl("input","input",-1,30)
GuiSetControl("edit","edit",-1,0,-1, 75)

GuiSetControl("icon","Eiffel tower.ico",-200,-30)
GuiSetControlNotify(-1,$GUI_CLOSE)   ; to force closing not default for "icon" control
GuiSetControl("pic",@Scriptdir & "\Splash.jpg",-180,-30)

GuiSetControl("button", "button1",  0,-1, 50,20); 50 width
GuiSetControl("button", "button2",  0,-1); next cell 50 width

$n=GuiSetControl("date", "date1",  -100,0,230); next cell 50 width
;GuiSetControlNotify(-1,2)

While GuiMsg () >0   ; will display an empty dialog box
$n=GuiRead()
msgbox(0,"click=" & $n, GUIRead($n))
wend

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I don't understand why with the radio box inside a group control the tab is not working anymore.

Because I removed it. We _could_ have it so that a group control automatically starts a control grouping but you still have to call SetGroup to tell it where the group ends (or like people were doing in the previous version creating an offscreen group control purely to end a group - yuk). Much better I think to have a group box as a purely visual cue (like the Visual C resource editor) and to define the underlying groups manually.

In your example it probably works OK as you are creating two group controls after each other, but try and create a dialog with a group control that contains 2 radio buttons and also has a couple of radio buttons outside the box like this:

#include <GUIconstants.au3>

Opt("GUICoordMode", 1)
Opt("GUINotifyMode", 1)
GUICreate("Radio Box Demo", 400,280)

; Create the controls
$group_1 = GUISetControl("group", "Group 1", 30, 90, 100, 160)
GUISetGroup()
$radio_1 = GUISetControl("radio", "Radio &0", 50, 120, 70, 20)
$radio_2 = GUISetControl("radio", "Radio &1", 50, 150, 60, 20)
$radio_3 = GUISetControl("radio", "Radio &2", 50, 180, 60, 20)
GUISetGroup()
$radio_4 = GUISetControl("radio", "Radio &A", 140, 120, 70, 20)
$radio_5 = GUISetControl("radio", "Radio &B", 140, 150, 60, 20)
$radio_6 = GUISetControl("radio", "Radio &C", 140, 180, 60, 20)

; Set the defaults (radio buttons clicked, default button, etc)
GUISetControlEx($radio_1, $GUI_CHECKED)
GUISetControlEx($radio_6, $GUI_CHECKED)


GuiShow()

; In this message loop we use variables to keep track of changes to the radios, another
; way would be to use GuiRead() at the end to read in the state of each control
While 1
   $msg = GuiMsg()
   Select
      Case $msg = -3
         Exit
   EndSelect
WEnd

Try it without the SetGroup() function in an older version and you can see that all the radio buttons inside and outside the group are linked and also see what happens to the tab order as after you select a couple of buttons - initially you can tab between all the radio buttons but after clicking on a couple of them the tab order changes to be what it is supposed to be (only one radio button per group should ever have TABSTOP and you use the arrow keys to move between them).

Edited by Jon

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

We could have GuiSetControl("Group","") as for the tab control to close :D

; Create the controls
$group_1 = GUISetControl("group", "Group 1", 30, 90, 100, 160)
$radio_1 = GUISetControl("radio", "Radio &0", 50, 120, 70, 20)
$radio_2 = GUISetControl("radio", "Radio &1", 50, 150, 60, 20)
$radio_3 = GUISetControl("radio", "Radio &2", 50, 180, 60, 20)

$group_2 = GUISetControl("group", "Group 2", 30, 90, 100, 160)
$radio_4 = GUISetControl("radio", "Radio &A", 140, 120, 70, 20)
$radio_5 = GUISetControl("radio", "Radio &B", 140, 150, 60, 20)
$radio_6 = GUISetControl("radio", "Radio &C", 140, 180, 60, 20)

GUISetControl("group", "")

; Set the defaults (radio buttons clicked, default button, etc)
GUISetControlEx($radio_1, $GUI_CHECKED)
GUISetControlEx($radio_6, $GUI_CHECKED)
Edited by jpm

Share this post


Link to post
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
Sign in to follow this  
Followers 0