Code: Select all
q::
hCtl := ControlGetHwnd("Edit1", "ahk_class Notepad")
hCtl2 := ControlGetHwnd("", "ahk_id " hCtl) ;doesn't work in v2.0-a100 (does work in v2.0-a099)
MsgBox(A_AhkVersion "`r`n" hCtl "`r`n" hCtl2)
return
Code: Select all
q::
hCtl := ControlGetHwnd("Edit1", "ahk_class Notepad")
hCtl2 := ControlGetHwnd("", "ahk_id " hCtl) ;doesn't work in v2.0-a100 (does work in v2.0-a099)
MsgBox(A_AhkVersion "`r`n" hCtl "`r`n" hCtl2)
return
Could you provide another reason, that is slightly better than just saying "I always did it like this"?jeeswg wrote: ↑28 Oct 2018, 12:13- Ever since I started using AutoHotkey, if you want to use a control hWnd in a ControlXXX function, you use "ahk_id " hCtl in the *WinTitle* parameter.
- (Perhaps it would make sense if you could also do this in the *Control* parameter. But it would still be useful if WinTitle could continue to handle both control and window hWnds.)
Also, the WinTitle parameter supports ahk_id %ControlHwnd% for WinXXX functions:To operate upon a control's HWND (window handle), leave the Control parameter blank and specify ahk_id %ControlHwnd% for the WinTitle parameter
Code: Select all
q::
hCtl := ControlGetHwnd("Edit1", "A")
vCtlClass := WinGetClass("ahk_id " hCtl)
WinGetPos(vCtlX, vCtlY, vCtlW, vCtlH, "ahk_id " hCtl)
vCtlPos := Format("x{} y{} w{} h{}", vCtlX, vCtlY, vCtlW, vCtlH)
MsgBox(vCtlClass "`r`n" vCtlPos)
return
A control's handle (HWND) can be used as a valid and unique control identifier in the Control parameter know. It doesn't need to be and should not be used in the WinTitle parameter of Control functions. (Besides "two-way compatible conversion logic" it doesn't make sense.)a100 wrote: Changed usage of Control parameter with Control functions and SendMessage/PostMessage.
- Can be a HWND (integer)
- Can be an object with a HWND property
- Mandatory in most cases
- Omit to use target window itself (ahk_parent is removed)
- Blank values are invalid (never default to topmost control)
lexikos wrote:Note: Specifying a window (WinTitle) by HWND still requires ahk_id for now. WinTitle will get similar treatment to Control in a future update.
Code: Select all
g := guicreate(,'hello')
b := g.addbutton('w200', 'hello')
detecthiddenwindows true
msgbox controlgethwnd('hello', 'ahk_id' g.hwnd) '`n' b.hwnd '`n' g.hwnd '`n' wingettext('ahk_id' g.hwnd)
I guess it is done this way because the ambiguity is empirically known to be insignificant.it was simply unthinkable for me that the text option was available directly like this.
- Let's say someone intentionality/unintentionally put a control hWnd in the WinTitle parameter, what would be the most useful behaviour? To allow it.just me wrote:A control's handle (HWND) can be used as a valid and unique control identifier in the Control parameter [now]. It doesn't need to be and should not be used in the WinTitle parameter of Control functions.
Code: Select all
q:: ;Internet Explorer - get find bar text
hCtl := ControlGetHwnd("FindBarClass1", "A")
vText := ControlGetText("Edit1", "ahk_id " hCtl)
MsgBox(vText)
return
Code: Select all
vText := ControlGetText("Edit1", "ahk_id " hWnd " ahk_dhw 0")
To tell you you made a mistake.- Let's say someone intentionality/unintentionally put a control hWnd in the WinTitle parameter, what would be the most useful behaviour?To allow it.
That makes sense in a way but then again causes issues with ClassNN.- Besides, occasionally you want to refer a control within a control within a window, necessitating a control hWnd to be used in the WinTitle parameter.
It's not needed since you have the absolutely unambigous option to pass an object containing the hWND parameter.- No-one's said this directly yet but perhaps you believe that ahk_id is no longer needed in AHK v2, since you can specify an hWnd directly.
Instead you force the hWND to be a string.- ahk_id is also useful because it means you do not have to force the hWnd to be of numeric type. E.g. I often operate on comma-separated lists of hWnds via an InputBox or via the selected text.
I plan to rewrite scripts rather than maintain any of the old ones.- Btw does anybody seriously want to downplay the cost of removing ahk_id etc from every script ever written in AutoHotkey?
No one said a control's hwnd can't be used in the wintitle parameter, the point is that the traget window / control is not considered in the search, the search is conducted on the controls of the taget window / control. Your script should work if this FindBarClass1 control has a control with classNN Edit1.Besides, occasionally you want to refer a control within a control within a window, necessitating a control hWnd to be used in the WinTitle parameter.
This is what I guessed you thought your code was supposed to mean, the fact that the parameter isn't optional should hint to you that you should ask for help on how to use the function instead of claiming there is an issue, And no, it doesn't make sense.All things considered, IMO, 'Control' as a blank string makes sense as omitted (not an hWnd/a ClassNN/text to search for).
It is off topic. The documentation has an actual valid example of combining ahk_id with other criterias, see Mulitple criteria. In any case, we can only hope that this ahk_xxx-mess gets replaced by something more readable.No-one's said this directly yet but perhaps you believe that ahk_id is no longer needed in AHK v2, since you can specify an hWnd directly.
Why do you continue to fight progress?Btw does anybody seriously want to downplay the cost of removing ahk_id etc from every script ever written in AutoHotkey?
because all he cares about is writing 2 way compatible scripts, despite the very specific quote on the AHK v2 page:
Return to “AutoHotkey Development”
Users browsing this forum: No registered users and 18 guests