The function will then read the received name from the button that called the function, where the function then have different outcome depending on the name or text the last clicked button had. I cannot figure out how to use the GuiControl.Name in AHK v2.
Code: Select all
; A_GuiControl is used in AHK v1 to get the value from the last clicked button - How would I do this in AHK 2 when A_GuiControl is now not existing?
Gui, 1: add, text,X10 y9 ,Several Buttons - using same subroutine:
Gui, 1: add, Button, w80 x10 y+10 vFirst_A_FF7777_Red gClickButton, Button A
Gui, 1: add, Button, w80 x+10 yp+0 vSecond_B_77FF77_green gClickButton, Button B
Gui, 1: add, Button, w80 x+10 yp+0 vThird_C_B0E0FF_blue gClickButton, Button C
Gui, 1: add, Button, w80 x+10 yp+0 vFourth_D_F088FF_lilac gClickButton, Button D
Gui, 1: add, Button, w80 x+10 yp+0 vFifth_E_F0F070_yellow gClickButton, Button E
Gui, 1: Add, Progress, Background202020 x10 y+8 w440 h28 cFFFFFF vColorBox, 100
Gui, 1: Add, Text, BackgroundTrans x10 yp+3 w440 h28 center vTextinfo, Press a button
Gui, 1: Show
ClickButton:
{ ; Same subroutine for each button. The v-ID (A_GuiControl) will be split into 4 useful variables.
Var := StrSplit(A_GuiControl, "_")
_btn := Var[1]
_val := Var[2]
_col := Var[3]
_cnm := Var[4]
ButtonFunctions(_btn,_val,_col,_cnm)
Return
}
ButtonFunctions(_btn_,_val_,_col_,_cnm_)
{ ; This is a simple function with 4 local variables.
Gui, Font, s12 w700,
GuiControl Font, Textinfo ; Update the font in the guicontrol vTextinfo
GuiControl, +c%_col_%, ColorBox, 100 ; set_color on the 100% filled progress bar
GuiControl, , Textinfo, %_btn_% button (%_val_%) pressed. Color is now %_cnm_%. ; Update the Gui text
Return
}