ControlXXX functions

Discuss the future of the AutoHotkey language
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

ControlXXX functions

28 Jan 2018, 10:14

- I've thought of some proposals for streamlining the ControlXXX functions.
- I'm not particularly concerned re. what the final syntax should be, but I think that these proposals outline a coherent system that allows for more readable scripts and for sensibly-named functions to be added in future.

GENERAL POINTS
XXXChoose (index)
XXXChooseString
XXXGetChoice (to return index not string)
XXXGetChoiceString (new)
XXXFindItem

[EDIT: Or:]
XXXChooseIndex
XXXChoose (string)
XXXGetChoiceIndex
XXXGetChoice (to return string)
XXXFindItem

[note: potentially these could all be part of XXXGetItems/XXXSetItems instead, but they might be simpler as separate functions]
[note: potentially XXXChoose/XXXChooseString, XXXGetChoice/XXXGetChoiceString could be combined by having a parameter which specifies return string instead of index]

LEAVE AS THEY ARE [enabled/style/visible/hWnd]
ControlGet, Enabled -> ControlGetEnabled
Control, Disable -> ControlSetEnabled
Control, Enable -> ControlSetEnabled

ControlGet, Visible -> ControlGetVisible
Control, Hide -> ControlHide
Control, Show -> ControlShow

ControlGet, Style -> ControlGetStyle
ControlGet, ExStyle -> ControlGetExStyle
Control, Style -> ControlSetStyle
Control, ExStyle -> ControlSetExStyle

ControlGet, Hwnd -> ControlGetHwnd

LEAVE AS THEY ARE [further (were never subcommands)]
ControlClick
ControlFocus
ControlGetFocus
ControlGetPos
ControlGetText
ControlMove
ControlSend
ControlSendText
ControlSetText

CHANGE EDIT CONTROL FUNCTIONS
ControlGet, CurrentCol -> ControlGetCurrentCol [make it: EditGetCurrentCol]
ControlGet, CurrentLine -> ControlGetCurrentLine [make it: EditGetCurrentLine]
ControlGet, LineCount -> ControlGetLineCount [make it: EditGetLineCount]
ControlGet, Line -> ControlGetLine [make it: EditGetLine]
ControlGet, Selected -> ControlGetSelected [make it: EditGetSelected]
Control, EditPaste -> ControlEditPaste [make it: EditPaste]

BUTTON CONTROLS [rename to allow more Btn functions in future][either Btn or Button]
ControlGet, Checked -> ControlGetChecked [make it: BtnGetChecked]
Control, Check -> ControlSetChecked [make it: BtnSetChecked]
Control, Uncheck -> ControlSetChecked [make it: BtnSetChecked]

COMBOBOX/LISTBOX/LISTVIEW [rename to allow more CB/LB/LV functions in future]
ControlGet, Choice -> ControlGetChoice [make it: XXXGetChoice (index)/XXXGetChoiceString where XXX=CB/LB][note: XXXGetChoice split into 2 functions to return index/string]
Control, Choose -> ControlChoose [make it: XXXChoose where XXX=CB/LB]
Control, ChooseString -> ControlChooseString [make it: XXXChooseString where XXX=CB/LB]
Control, Add -> ControlAddItem [make it: XXXAddItem where XXX=CB/LB]
Control, Delete -> ControlDeleteItem [make it: XXXDeleteItem where XXX=CB/LB]
ControlGet, FindString -> ControlFindItem [make it: XXXFindItem where XXX=CB/LB]
ControlGet, List -> ControlGetList [make it: XXXGetItems where XXX=CB/LB/LV]
Control, HideDropDown -> ControlHideDropDown [make it: CBHideDropDown]
Control, ShowDropDown -> ControlShowDropDown [make it: CBShowDropDown]

TAB CONTROLS
Control, TabLeft -> ControlSetTab [make it: TabChoose]
Control, TabRight -> ControlSetTab [make it: TabChoose]
ControlGet, Tab -> ControlGetTab [make it: TabGetChoice (index)]

LOW PRIORITY: RESTORE THE FOLLOWING FOR INTERNAL/EXTERNAL CONTROLS
[either as LV_/SB_/TV_ or as LV/SB/TV]
[change the parameters so that any control can be specified, e.g. 'Control, WinTitle' etc]
[I'm not particularly concerned about changing the function names]
LV_Add
LV_Delete
LV_DeleteCol
LV_GetCount
LV_GetNext
LV_GetText
LV_Insert
LV_InsertCol
LV_Modify
LV_ModifyCol
LV_SetImageList

SB_SetIcon
SB_SetParts
SB_SetText
StatusBarGetText [make it able to handle any control, not just 'msctls_statusbar321']
StatusBarWait [make it able to handle any control, not just 'msctls_statusbar321']

TV_Add
TV_Delete
TV_Get
TV_GetChild
TV_GetCount
TV_GetNext
TV_GetParent
TV_GetPrev
TV_GetSelection
TV_GetText
TV_Modify
TV_SetImageList

Thanks for reading.

why was LoopParse (no space) removed? - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=41821&p=190742#p190742
- For certain ControlXXX functions, specific to certain control types, the most sensible thing to do may be to create functions with the control type in the name.
- One reason is that when I look at, for example, ControlShowDropDown/ControlGetCurrentLine/ControlGetSelected/ControlAddItem, I instantly think, which control type is that for, will it work with the control I'm working with.
- Seeing multiple functions specific to a particular type of control, identified by their prefixes, makes it easier to follow the logic of the script.
- I would say as a rule of thumb, a ControlXXX function should only be called ControlXXX if it works with six control types or more.
- People will naturally be reluctant to add more ControlXXX functions to AHK, with the 'Control' prefix, that only work for one type of control.
- There were a lot of listview/treeview functions in AHK v1, and so having LV/TV prefixes would be consistent with this.
Link:
Control Functions
https://lexikos.github.io/v2/docs/commands/Control.htm
Last edited by jeeswg on 11 Oct 2019, 03:54, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ControlXXX functions

06 Oct 2018, 18:31

The recent changes (as usual) look great:
AutoHotkey v2 alpha (UPDATES) - Page 3 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 06#p242306

One point of interest is that I'm a bit concerned that the Control and WinTitle parameters are getting too complicated.
List of Control Functions | AutoHotkey v2
https://lexikos.github.io/v2/docs/comma ... #Parameter

Here would be my suggestions:

> if Control parameter is String/Integer/Float:
if looks numeric/integral: hWnd
else if blank/omitted: use target window
else: ClassNN

note: use 'ahk_text' to specify text that the control contains (rarely used? e.g. I never use it)
note: use 'ahk_text' to specify literal control text that looks numeric
note: use 'ahk_mode R' to specify a ClassNN using RegEx (more commonly needed in recent times)

> if WinTitle parameter is String/Integer/Float:
if looks numeric/integral: hWnd
else if A: use active window
else: window title text

note: use 'ahk_title' to specify literal window title text that looks numeric
note: use 'ahk_text' to specify text that the window contains (rarely used? especially since ahk_exe) (or use the WinText parameter)

> if Control/WinTitle parameter is Object:
if object has Hwnd property containing String/Integer/Float (that looks numeric): hWnd
else: error

==================================================

> Re. ahk_dhw/ahk_mode:
From:
Wish List 2.0 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 13&t=36789
AHK_DHW (V/VH/H) AND AHK_MODE (S/C/X/E/R)

- Since the letters HV and CERSX don't overlap, ahk_mode could be used to perform both roles.
- E.g. use A_DetectHiddenWindows unless H and/or V is seen. E.g. use A_TitleMatchMode unless one of S/C/X/E/R is seen.
> Re. blank parameters:
From the same link:
- [MODIFY] ControlGetLine [if Line omitted/blank, return text of current line]
- [MODIFY] ControlXXX [AHK v2: a blank Control parameter equivalent to omitting parameter]
- [MODIFY] SubStr [a blank Length parameter equivalent to omitting parameter]
> In general:
- I think it's good for functions to not discriminate based on type, and I think it's good for functions to allow blank/omitted parameters to be interchangeable.
- Exceptions can be fine e.g. MsgBox/InputBox window title (blank = blank title, omitted = default title).

- [EDIT:] Perhaps an 'A_ControlMatchMode' variable could be useful, cf. A_TitleMatchMode.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ControlXXX functions

22 Sep 2019, 14:45

It could be good to add WinGetEnabled/WinGetVisible, to complete:
ControlGetEnabled/___/ControlSetEnabled/WinSetEnabled
ControlGetVisible/___/ControlShow/WinShow/ControlHide/WinHide

(Potentially, ControlGetChecked/XXXGetEnabled/XXXGetVisible, could use 'Is' rather than 'Get'. But it might be simpler to use 'Get'.)

(Other functions might be: WinGetOwner/WinGetParent/WinGetNonChildParent.)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 71 guests