So here it is: Creating a slider using your own graphics - 2 image files. One for the bar, and one for the thumb (the bit that moves)
You have the sliderbar and thumb, plus an edit box with an updown control. The thumb, editbox and updown controls all call the same sub-routine when they are changed.
The value of the editbox will change when you move the slider. The slider position will change when you use the up down arrows, or enter a value in the editbox. Also, you can click anywhere on the bar (just like a standard slider control)
You must make sure to name them as follows for this to work:
The thumb:- Any name - eg: Slider - This is the root from
The Bar :- eg: Sliderbar which the others are
The editbox eg: Sliderbox based.
The updown control eg Sliderupd
Also, there is a function that will automatically put a scale under the slider.
Code:
addpng(sliderbariconum,"backgroundtrans gmovecustomslider v" . barname . " x" . sliderbarxpos . " yp",hModule)
guicontrolget,tbarpos,pos,%barname%
sliderstartpos:=sliderbarxpos+((sliderstartval//maxrange)*tbarposw)
addpng(sliderthumbiconum,"backgroundtrans v" . fire . " x" . sliderstartpos . " yp gmovecustomslider",hModule)
;keywait,enter,T5 D
gui,add,edit,v%editname% backgroundtrans gmovecustomslider c%txtcolor% H%slider_height% yp-8 x%gapafterslider% w%edit_width% limit%edit_limit% number
gui,add,updown,v%updownname% gmovecustomslider range%minrange%-%maxrange%, %sliderstartval%
scale(%barname%,200,maxrange,0,tbarposw,sliderbarxpos,tbarposy+8) ; This adds the scale
The addpng, is just a function that adds a .png file from a resource file.dll. But as just think of it as adding a picture normally.
Code:
movecustomslider:
;msgbox afj
gui ,1:submit, nohide
; Find out what control called this subroutine
temptxt:=substr(A_guicontrol,-2,3)
if (temptxt = "box" or temptxt = "upd" or temptxt = "bar")
stringtrimright,tcontrolname,a_guicontrol,3
else
tcontrolname:=a_guicontrol
tbarname:=tcontrolname . "bar"
teditname:=tcontrolname . "box"
tupdname:=tcontrolname . "upd"
tmaxval:=maxrange
if (a_guicontrol=teditname or a_guicontrol=tupdname) ; User clicked on edit or updown control
{
guicontrolget,tcontrolval,,%a_guicontrol% ; store value of control to a variable
tnewsliderpos:=0
tsetcontrolname:=a_guicontrol=teditname ? tupdname : teditname
tcontrolval:=tcontrolval="" ? 0 : tcontrolval
tcontrolval:=tcontrolval>maxrange ? maxrange : tcontrolval
guicontrol,1:,%tsetcontrolname%,%tcontrolval% ; set valuse of corres control
;position custom made slider
guicontrolget,tbarpos,pos,%tbarname% ;get pos (x,y,width and height) of the 'bar' of the slider
tnewsliderpos:=ceil(tbarposx+(tbarposw*(tcontrolval/tmaxval)))
guicontrol, 1:move,%tcontrolname%, x%tnewsliderpos% y%tbarposy%
}
else
{ ;User clicked on slider thumb or bar
tslidepos:=0
coordmode,mouse,relative
guicontrolget,tbarpos,pos,%tbarname%
maxright:=(tbarposx+tbarposw) ; ycoord of right edge of slider bar
loop
{
mousegetpos,mousex,mousey ;get current mouse pos
if (mousex>maxright) ;dont allow the value to go out of range
mousex:=maxright
if (mousex<tbarposx)
mousex:=tbarposx
tnewval:=ceil(((mousex-tbarposx)/tbarposw) * tmaxval) ;new value of slider
;msgbox ,,,tnewval:=ceil(((%mousex%-%tbarposx%)/%tbarposw%) * %tmaxval%) `n`n =%tnewval%`n`nguicontrol,1:move,%tcontrolname%, x%mousex% y%tbarposy%`n`n%A_GuiControl%
guicontrol,1:move,%tcontrolname%, x%mousex% y%tbarposy% ;move control with mouse
ttposx:=mousex-6
ttposy:=tbarposy-5
tooltip,%tnewval%,ttposx,ttposy
if (checkkeydown("LButton") or (a_guicontrol=tbarname)) ;check left button is still down
{
break ; or if user clicked on bar exit loop
}
}
tooltip
guicontrol,1:,%teditname%,%tnewval% ;update values of the edit box
guicontrol,1:,%tupdname%,%tnewval%
;msgbox,,,guicontrol.1:.%tupdname%.%tnewval%::%A_GuiControl%
}
return
....and here is the scale function....
Code:
scale(slidebar,bigsteps,max,min =0,w =999,x =999,yy =999,startpostatmin =false, smscale ="smscale.bmp")
{
global
static uid:=1
xpox:=0
varname:=""
guicontrolget,scale,pos,%slidebar%
w:=w=999 ? scalew : w
x:=x=999 ? scalex : x
yy:=yy=999 ? scaley :yy
smsteps:=50
smintervals:=max/smsteps
bigintervals:=max/bigsteps
if startpostatmin
bigstartpostlabel:=min
else
bigstartpostlabel:=mod(min,bigsteps)=0 ? min : ((min//bigsteps)+1)*bigsteps
smposts:=smintervals+1
bigposts:=bigintervals+1
unitdist:=(w/(max-min))
bigintervaldistance:=unitdist*bigsteps
smintervaldistance:=unitdist*smsteps
bigstartpost:=startpostatmin=true ? 0 : (mod(min,bigsteps))*unitdist
; loop %smposts%
; {
; yy:=a_index=1 ? yy : "p"
; xpox:=x+(smintervaldistance*(a_index-1))
; gui,1:add,picture,y%yy% x%xpox% w.5 h7,%smscale%
; ;msgbox,,,gui.1:add.picture.y%yy% x%xpox% w1 h3.%smscale%`n`n`nxpox:=%x%+(%smintervaldistance%*(%a_index%-1))::%xpox%,.5
; }
loop %bigposts%
{
yy:=a_index=1 ? yy : "p"
xpox:=x+bigstartpost+(bigintervaldistance*(a_index-1))
if startpostatmin
bigpostlabel:=min+(bigsteps*(a_index-1))
else
bigpostlabel:=((bigstartpostlabel//bigsteps)+(a_index-1))*bigsteps
varname=scale_%uid%_%a_index%
gui, add, text, x%xpox% y%yy% backgroundtrans v%varname%,%bigpostlabel%
guicontrolget,tempos,pos,%varname%
guicontrol,1:move,%varname%, % "x" temposx-(temposw/2)
;msgbox,,,%tempww%`n`n%varname%,.5
}
uid++
return
}