Code: Select all
/*
Input values:
Edit1:=new NumberEdit(1,"w200","Numbers Only",1)
| | | | |-Negative Possible
| | | |---------Pre-Entered Text
| | |--------------------Control Options
| |-------------------------Window Name/Number
|-----------------------------------------------Object to get values from
Getting Information:
Value:=Edit1[]
Setting Values:
Edit1.Value(44) ;Changes the value
*/
Edit1:=new NumberEdit(1,"w200","Numbers Only")
Edit2:=new NumberEdit(1,"w200","Numbers Only")
Edit3:=new NumberEdit(1,"w200","Numbers Only")
Gui,Add,Button,gShowValues Default,Show Values
Gui,Add,Button,gSetValue Default,Set Value To 23
Gui,Show
return
SetValue:
Edit1.Value(23)
Edit2.Value(23)
Edit3.Value(23)
return
ShowValues:
MsgBox,% Edit1[] "`n" Edit2[] "`n" Edit3[]
return
GuiClose:
GuiEscape:
ExitApp
return
Code: Select all
Class NumberEdit{
__New(Gui,Options,Text="",Negative:=0){
static Count:=0
static
Gui,%Gui%:Add,Edit,% Options " gNumberEdit.Notify hwndHWND vNumber" ++Count,%Text%
this.HWND:=HWND,this.Gui:=Gui,obj:=NumberEdit["Number" Count]:=[],obj.Negative:=Negative,obj.HWND:=HWND,obj.GUI:=Gui
return this
}__Get(){
if(WinExist("ahk_id" this.HWND)){
ControlGetText,Number,,% "ahk_id" this.HWND
if(RegExReplace(Number,"(,|-|\.)")~="(\D)"=0)
return Number
}
}Value(Value:=""){
GuiControl,% this.Gui ":",% this.HWND,%Value%
}Notify(){
this:=NumberEdit[A_GuiControl]
ControlGetText,Number,,% "ahk_id" this.HWND
SendMessage,0xB0,,,,% "ahk_id" this.HWND
pos:=ErrorLevel&0xff,RegExReplace(Number,"-",,CheckNegative)
if(this.Negative)
(Mod(CheckNegative,2)?(Negative:="-",pos++):(pos--))
Number:=RegExReplace(Number,"[^\d|\.]",,Count)
if(Count){
GuiControl,% this.Gui ": +g",% this.HWND
GuiControl,,% this.HWND,%Negative%%Number%
SendMessage,0xB1,% pos-1,% pos-1,,% "ahk_id" this.hwnd
GuiControl,% this.Gui ": +gNumberEdit.Notify",% this.HWND
}
}
}