I have a script with 36 buttons (An app for a MIDI controller keyboard). Narrowing it down to use only one gButton label really minimizes hundeds of rows of code...
This example has 5 buttons,
- each with 3 different "variables" in it! the vID is an A_GuiControl that can be used as values to process in the gLabel.
- the buttons are of the same type so they can go to the same gLabel!
Code: Select all
#SingleInstance Force
SetWorkingDir, %A_ScriptDir%
Gui, 1: add, text,X10 y9 ,Several Buttons - using same subroutine:
Gui, 1: add, Button, w60 x10 y+10 vfirst_1_FF7777 gClickButton, Button A
Gui, 1: add, Button, w60 x+10 yp+0 vsecond_2_77FF77 gClickButton, Button B
Gui, 1: add, Button, w60 x+10 yp+0 vthird_3_B0E0FF gClickButton, Button C
Gui, 1: add, Button, w60 x+10 yp+0 vfourth_4_F088FF gClickButton, Button D
Gui, 1: add, Button, w60 x+10 yp+0 vfifth_5_F0F070 gClickButton, Button E
Gui, 1: Add, Progress, Background202020 x10 y+8 w340 h20 cFFFFFF vColorBox, 100
Gui, 1: Add, Text, BackgroundTrans x10 yp+3 w340 h20 center vTextinfo, Press a button
Gui,1: Show, , ButtonsSubroutine
Return
ClickButton:
{ ; Same subroutine for each button. The v-ID (A_GuiControl) will be split into 3 useful variables.
Value := StrSplit(A_GuiControl, "_")
set_label := Value[1]
set_value := Value[2]
set_color := Value[3]
; Now use those Global variables. For learning purposes; Call a function:
CalcFunction(set_label,set_value,set_color)
Return
}
CalcFunction(_Name_,_value_,_color_)
{ ; This is a simple function with 3 local variables.
GuiControl, +c%_color_%, ColorBox, 100 ; set_color on the 100% filled progress bar
GuiControl, , Textinfo, The %_Name_% button: (%_value_%) was pressed. ; Update the Gui text
Return
}
GuiClose:
Guiescape:
exitapp