I have been using Polyethene's Command Functions library which is supposed to act as a replacement for allot of commands, The AutoHotkey docs recommends the library HERE. I have made use of it allot but I am struggling to make use of one function though, which is GuiControlGet
, a replacement for the GuiControlGet command.
In this example, I want to get the width of the Text
control, I can find it with the GuiControlGet
command but its functional opposite fails with an error:
var := "Hello world"
Gui HUD:New, +AlwaysOnTop +ToolWindow -Caption +HwndMainHwnd, hudWin
Gui HUD:Font,s14,Consolas
Gui, Add, Text,,% var
GuiControlGet, OutputVar, Pos,% var
Gui HUD:Show, x300 y300 w300 h300
msgbox,% outputVarW ; returns the width of "Gui, Add, Text,,% var" control
OutPut := GuiControlGet("Pos", "var") ; I get error: ==> Warning: This variable has not been assigned a value. Specifically: v (a local variable)
msgbox,% OutPutW ; Nothing shown
GuiControlGet(Subcommand = "", ControlID = "", Param4 = "") {
GuiControlGet, v, %Subcommand%, %ControlID%, %Param4%
Return, v
}
Any help would be greatly appreciated!
You may try this way:
Global v ; <---
var := "Hello world"
Gui HUD:New, +AlwaysOnTop +ToolWindow -Caption +HwndMainHwnd, hudWin
Gui HUD:Font,s14,Consolas
Gui, Add, Text,,% var
; Gui HUD:Show, x300 y300 w300 h300
GuiControlGet("Pos", var) ; <--- var cant be between double quotes
msgbox % vw "`n"
. vh "`n"
. vx "`n"
. vy
GuiControlGet(Subcommand = "", ControlID = "", Param4 = "") {
GuiControlGet, v, %Subcommand%, %ControlID%, %Param4%
Return, v
}
Or this...
var := "Hello world"
Gui HUD:New, +AlwaysOnTop +ToolWindow -Caption +HwndMainHwnd, hudWin
Gui HUD:Font,s14,Consolas
Gui, Add, Text,,% var
; Gui HUD:Show, x300 y300 w300 h300
MsgBox % GuiControlGet("Pos", var)["w"] "`n"
. GuiControlGet("Pos", var)["h"] "`n"
. GuiControlGet("Pos", var)["x"] "`n"
. GuiControlGet("Pos", var)["y"]
; Another way
output:= GuiControlGet("Pos", var)
MsgBox % output["w"] "`n"
. output["h"] "`n"
. output["x"] "`n"
. output["y"]
GuiControlGet(Subcommand = "", ControlID = "", Param4 = "") {
Params := {w : 0, h : 0, x : 0, y : 0 }
GuiControlGet, v, %Subcommand%, %ControlID%, %Param4%
for value, i in params
params[value] := v%value%
Return params
}