A very nice Horizontal Slider.. How to make it vertical instead

Get help with using AutoHotkey and its commands and hotkeys
keylo
Posts: 29
Joined: 21 Oct 2020, 21:03

A very nice Horizontal Slider.. How to make it vertical instead

Post by keylo » 16 Jan 2021, 15:09

This is a code for a very nice horizontal slider from tmplinshi I think (https://www.autohotkey.com/boards/viewtopic.php?t=80476) .

I am trying hard to make it a vertical slider, without success.
my understanding of " Class" is limited for now.

Can somebody help ?
image.png
image.png (6.28 KiB) Viewed 222 times

Code: Select all

Gui, Color, 0x282D41
hBitmap := Create_sliderthumb_png()
; hBitmap := LoadPicture("sliderthumb.png")
slider := new CustomSlider("y20 w400 h3 BackGround0x454C5F c0x2666B5", 20, hBitmap)
Gui, Show, h100

MsgBox, % slider.pos ; get current pos
slider.pos := 90 ; set new pos
Return

GuiClose:
ExitApp

; based on http://www.autohotkey.com/board/topic/81144-progress-bar-slider/?p=516891
class CustomSlider
{
	__New(Options := "", val := "", hBitmap_thumb := "", ShowTooltip := false) {
		if !RegExMatch(Options, "i)\bBackground\w+\b") {
			if RegExMatch(Options, "i)\bc\K\w+", bkColor)
				bkOpt := "Background" bkColor
		}
		Gui, Add, Progress, h1 %Options% %bkOpt% hwndHPROG Disabled -E0x20000, % val

		Gui, Add, Text, xp yp-10 h24 wp BackgroundTrans HWNDhpgTrigger, 
		; Gui, Add, Text, x+15 w30 HWNDhRightText, %val%

		if RegExMatch(Options, "i)\bRange\K([\d-]+)-([\d-]+)", rng)
			this.rng_radio := Abs(rng2 - rng1)/100
		else
			this.rng_radio := 1

		GuiControlGet, pg, Pos, %HPROG%
		x := pgW * (val/this.rng_radio/100) + pgX

		Gui, Add, Pic, yp x%x% w8 h24 HWNDhBtn, % "HBITMAP:" hBitmap_thumb

		this.hProg := HPROG
		this.hBtn := hBtn
		this.pgVal := val
		this.ShowTooltip := ShowTooltip
		; this.hRightText := hRightText

		fn := this.OnClick.Bind(this)
		GuiControl, +g, %hBtn%, %fn%
		GuiControl, +g, %hpgTrigger%, %fn%
	}

	OnClick() {
		GuiControl, Focus, % this.hBtn

		hSlider := this.hProg

		pre_CoordModeMouse := A_CoordModeMouse
		CoordMode, Mouse, Relative

		MouseGetPos,,,, ClickedhWnd, 2

		GuiControlGet, SliderLine, %A_Gui%:Pos, % hSlider

		GuiControlGet, sliderVal, %A_Gui%:, %hSlider%
		V := sliderVal

		if this.ShowTooltip
			ToolTip, %sliderVal%

		ControlGet, Style, Style,,, ahk_id %hSlider%
		ControlGetPos, X, Y, W, H,, ahk_id %hSlider%

		VarSetCapacity(R, 8)
		SendMessage, 0x0407,, &R,, ahk_id %hSlider%
		R1 := NumGet(R, 0, "Int")
		R2 := NumGet(R, 4, "Int")
		
		LastV := (ClickedhWnd = this.hBtn) ? "" : sliderVal

		while (GetKeyState("LButton"))
		{
			Sleep, 10
			MouseGetPos, XM, YM
			V := (V:=(Style&0x4 ? 1-(YM-Y)/H : (XM-X)/W))>=1 ? R2 : V<=0 ? R1 : Round(V*(R2-R1)+R1)
			if (LastV="") {
				LastV := V
			} else if (V != LastV) {
				LastV := V
				if this.ShowTooltip
					ToolTip % V
				this.pos(SliderLineW, SliderLineX) := V
			}
		}

		if this.ShowTooltip
			ToolTip
		CoordMode, Mouse, %pre_CoordModeMouse%
	}

	pos[pgW := "", pgX := ""] {
		set {
			GuiControl,, % this.hProg, % value

			if !pgW
				GuiControlGet, pg, Pos, % this.hProg

			x := pgW * (value/this.rng_radio/100) + pgX
			; GuiControl, MoveDraw, % this.hBtn, x%x%
			GuiControl, Move, % this.hBtn, x%x%
			DllCall("InvalidateRect", "ptr", this.hBtn, "ptr", 0, "int", 0)

			this.pgVal := value
			; GuiControl,, % this.hRightText, % value
		}
		get {
			return this.pgVal
		}
	}
}

; ##################################################################################
; # This #Include file was generated by Image2Include.ahk, you must not change it! #
; ##################################################################################
Create_sliderthumb_png(NewHandle := False) {
Static hBitmap := 0
If (NewHandle)
   hBitmap := 0
If (hBitmap)
   Return hBitmap
VarSetCapacity(B64, 3864 << !!A_IsUnic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56gnSg98fnkgpPjp2Snnp1OPz3Umdx590z8mWtdUV29Z0PPnj8XdO5Mt1/3yfPe549d8Lxw9CL3Ytslt0utPa49R35w/eFIr1tv62X3y+1XPK509E3rO9Hv03/6asDVc9f41y5dn3m978bsG7duJt0cuCW69fh29u0XdwruTNxdeo94r/y+2v3qB/oP6n+0/rFlwG3g+GDAYM/DWQ/vDgmHnv6U/9OH4dJHzEfVI0YjjY+dHx8bDRq98mTOk+GnsqcTz8p+Vv9563Or59/94vtLz1j82PAL+YvPv655qfNy76uprzrHI8cfvM55PfGm/K3O233vuO+638e9H5ko/ED+UPPR+mPHp9BP9z7nfP78L/eE8/sl0p8zAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAB+SURBVHja7MoxDsFgAIDR1z/iFKZKNBylg7iEmgwOwiSRRuII3bhLO3Q2GUVE1CzR2sW3fi9qmkayOMVYIsMNB+zKPK2jUXaMUaLnvTvGAasPE/qYB8y0Nw0YdIBJ8KU/+DVw7vhVQNEBioB1y3xgH/DEEFtcccEGSZmn9WsAGtkbfQ0awwMAAAAASUVORK5CYII="
If !DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt", 0, "UInt", 0x01, "Ptr", 0, "UIntP", DecLen, "Ptr", 0, "Ptr", 0)
   Return False
VarSetCapacity(Dec, DecLen, 0)
If !DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt", 0, "UInt", 0x01, "Ptr", &Dec, "UIntP", DecLen, "Ptr", 0, "Ptr", 0)
   Return False
; Bitmap creation adopted from "How to convert Image data (JPEG/PNG/GIF) to hBITMAP?" by SKAN
; -> http://www.autohotkey.com/board/topic/21213-how-to-convert-image-data-jpegpnggif-to-hbitmap/?p=139257
hData := DllCall("Kernel32.dll\GlobalAlloc", "UInt", 2, "UPtr", DecLen, "UPtr")
pData := DllCall("Kernel32.dll\GlobalLock", "Ptr", hData, "UPtr")
DllCall("Kernel32.dll\RtlMoveMemory", "Ptr", pData, "Ptr", &Dec, "UPtr", DecLen)
DllCall("Kernel32.dll\GlobalUnlock", "Ptr", hData)
DllCall("Ole32.dll\CreateStreamOnHGlobal", "Ptr", hData, "Int", True, "PtrP", pStream)
hGdip := DllCall("Kernel32.dll\LoadLibrary", "Str", "Gdiplus.dll", "UPtr")
VarSetCapacity(SI, 16, 0), NumPut(1, SI, 0, "UChar")
DllCall("Gdiplus.dll\GdiplusStartup", "PtrP", pToken, "Ptr", &SI, "Ptr", 0)
DllCall("Gdiplus.dll\GdipCreateBitmapFromStream",  "Ptr", pStream, "PtrP", pBitmap)
DllCall("Gdiplus.dll\GdipCreateHBITMAPFromBitmap", "Ptr", pBitmap, "PtrP", hBitmap, "UInt", 0)
DllCall("Gdiplus.dll\GdipDisposeImage", "Ptr", pBitmap)
DllCall("Gdiplus.dll\GdiplusShutdown", "Ptr", pToken)
DllCall("Kernel32.dll\FreeLibrary", "Ptr", hGdip)
DllCall(NumGet(NumGet(pStream + 0, 0, "UPtr") + (A_PtrSize * 2), 0, "UPtr"), "Ptr", pStream)
Return hBitmap
}

User avatar
mikeyww
Posts: 5366
Joined: 09 Sep 2014, 18:38

Re: A very nice Horizontal Slider.. How to make it vertical instead

Post by mikeyww » 16 Jan 2021, 15:43

Code: Select all

Gui, Color, Black
Gui, Add, Slider, h200 Invert Vertical gValue vval, 20
Gui, Show,, Test
Return

Value:
MsgBox, 64, Value, %val%
Return

keylo
Posts: 29
Joined: 21 Oct 2020, 21:03

Re: A very nice Horizontal Slider.. How to make it vertical instead

Post by keylo » 17 Jan 2021, 00:28

Thanks mikeyww, But I don't like the default slider much. I prefer the slider above, I show in the first post. I am looking for a way to set it as vertical slider instaed horizontal. I am working on it and I will share my results.

User avatar
Hellbent
Posts: 1194
Joined: 23 Sep 2017, 13:34

Re: A very nice Horizontal Slider.. How to make it vertical instead

Post by Hellbent » 18 Jan 2021, 00:31

Requires the GDIP Library to run (Search GDI+ on this forum)

Included a vertical and horizontal example.

Code: Select all

;***************************************************************************************************
#Include <My Altered Gdip Lib>  ;<------       Replace with your copy of GDIP
;***************************************************************************************************
#SingleInstance, Force
#NoEnv
ListLines, Off
SetBatchLines, -1
OnExit, *ESC
SetControlDelay, -1
pToken := GDIP_StartUp()

;Slider 1 (Horz)
width1 := 400, height1 := 67, SliderMax := 150, SliderMin := 35, SliderWidth := width1 - 60
Gui, 1:+AlwaysOnTop -DPIScale
Gui, 1:Margin, 0, 0
Gui, 1:Add,Text, x0 y0 w%width1% h%height1% hwndTextHwnd1 0xE
Gui, 1:Add,Text, x30 y20 w%SliderWidth% h27 gAdjustSliderHorz Border
Gui, 1:Show,, horizontal 
DrawSliderHorZ( width1, height1, TextHwnd1 )

;Slider 2 (Vert)
width2 := 67, height2 := 400, SliderMax2 := 750, SliderMin2 := 112, SliderHeight := height2 - 60
Gui, 2:+AlwaysOnTop -DPIScale
Gui, 2:Margin, 0, 0
Gui, 2:Add,Text, xm ym w%width2% h%height2% hwndTextHwnd2 0xE
Gui, 2:Add,Text, x20 y30 w27 h%SliderHeight% gAdjustSliderVert
Gui, 2:Show,, vertical 
DrawSliderVert( width2, height2, TextHwnd2)

return
GuiClose:
2GuiClose:
GuiContextMenu:
2GuiContextMenu:
*ESC:: 
	GDIP_SHUTDOWN(pToken)
	ExitApp
	
AdjustSliderVert:
	LastY := "", Value2 := 0
	CoordMode, Mouse, Client
	while(GetKeyState("LButton")){
		sleep, 150
		MouseGetPos, tx, ty
		If(ty=LastY)
			continue
		LastY := ty
		
		(ty<=36)?(yPos := 30,Value2 := SliderMax2)
		:(ty>=364)?(yPos := 358,Value2 := SliderMin2)
		:(yPos := ty - 6, Value2 := floor( ( ty - 30 ) / ( ( SliderHeight - 6 ) / ( SliderMax2 - SliderMin2) ) - SliderMax2 ) * -1 ) 
		
		DrawSliderVert( width2, height2, TextHwnd2, yPos)
		ToolTip, % "Value: " Value2 
	}
	ToolTip,
	return
	
AdjustSliderHorz:
	LastX := "", Value := 0
	CoordMode, Mouse, Client
	while(GetKeyState("LButton")){
		sleep, 150
		MouseGetPos, tx, ty
		If(tx=LastX)
			continue
		LastX := tx
		(tx<=36)?(xPos := 30,Value := SliderMin)
		:(tx>=364)?(xPos := 358,Value := SliderMax)
		:(xPos := tx - 6,Value := floor( ( tx - 30 ) / ( ( SliderWidth - 6 ) / ( SliderMax - SliderMin ) ) + SliderMin) ) 
		
		DrawSliderHorZ( width1, height1, TextHwnd1, xPos )
		ToolTip, % "Value: " Value
	}
	ToolTip,
	return
	
DrawSliderVert( width, height, hwnd, y := 309){
	;Bitmap Created Using: HB Bitmap Maker
	pBitmap:=Gdip_CreateBitmap( Width , Height ) , G := Gdip_GraphicsFromImage( pBitmap ), Gdip_SetSmoothingMode( G , 2 )
	
	; Background
	Brush := Gdip_BrushCreateSolid( "0xFF282D41" ), Gdip_FillRectangle( G , Brush , -1 , -1 , Width + 2 , Height + 2 ), Gdip_DeleteBrush( Brush )
	; Slider Track
	Brush := Gdip_BrushCreateSolid( "0xFF454C5F" ), Gdip_FillRectangle( G , Brush , 30 , 30 , 7 , 340 ), Gdip_DeleteBrush( Brush )
	; Slider Track Border
	Pen := Gdip_CreatePen( "0xFF222222" , 1 ), Gdip_DrawRectangle( G , Pen , 30 , 30 , 7 , 340 ), Gdip_DeletePen( Pen )
	;Button 
	Brush := Gdip_BrushCreateSolid( "0xFF2565B3" ), Gdip_FillRoundedRectangle( G , Brush , 20 , y , 27 , 12 , 3 ), Gdip_DeleteBrush( Brush )
	Pen := Gdip_CreatePen( "0xFF222222" , 1 ), Gdip_DrawRoundedRectangle( G , Pen , 20 , y , 27 , 12 , 3 ), Gdip_DeletePen( Pen )
	; Fill Guage
	Brush := Gdip_BrushCreateSolid( "0xFF2565B3" ), Gdip_FillRectangle( G , Brush , 31 , y , 5 , 370 - y ), Gdip_DeleteBrush( Brush )
	
	hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap), SetImage(hwnd, hBitmap)
	Gdip_DeleteGraphics( G ), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
}

DrawSliderHorZ( width, height, hwnd, x := 214){
	;Bitmap Created Using: HB Bitmap Maker
	pBitmap:=Gdip_CreateBitmap( Width , Height ), G := Gdip_GraphicsFromImage( pBitmap ), Gdip_SetSmoothingMode( G , 2 )
	
	; Background
	Brush := Gdip_BrushCreateSolid( "0xFF282D41" ), Gdip_FillRectangle( G , Brush , -1 , -1 , Width + 2 , Height + 2 ), Gdip_DeleteBrush( Brush )
	; Slider Track
	Brush := Gdip_BrushCreateSolid( "0xFF454C5F" ), Gdip_FillRectangle( G , Brush , 30 , 30 , 340 , 7 ), Gdip_DeleteBrush( Brush )
	; Slider Track Border
	Pen := Gdip_CreatePen( "0xFF222222" , 1 ), Gdip_DrawRectangle( G , Pen , 30 , 30 , 340 , 7 ), Gdip_DeletePen( Pen )
	;Button 
	Brush := Gdip_BrushCreateSolid( "0xFF2565B3" ), Gdip_FillRoundedRectangle( G , Brush , x , 20 , 12 , 27 , 3 ), Gdip_DeleteBrush( Brush )
	Pen := Gdip_CreatePen( "0xFF222222" , 1 ), Gdip_DrawRoundedRectangle( G , Pen , x , 20 , 12 , 27 , 3 ), Gdip_DeletePen( Pen )
	; Fill Guage
	Brush := Gdip_BrushCreateSolid( "0xFF2565B3" ), Gdip_FillRectangle( G , Brush , 31 , 31 , x - 29 , 5 ), Gdip_DeleteBrush( Brush )
	
	hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap), SetImage(hwnd, hBitmap)
	Gdip_DeleteGraphics( G ), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
}


HTH

.
20210118020044.png
20210118020044.png (49.71 KiB) Viewed 125 times

keylo
Posts: 29
Joined: 21 Oct 2020, 21:03

Re: A very nice Horizontal Slider.. How to make it vertical instead

Post by keylo » 18 Jan 2021, 16:11

Hellbent, that's nice, thanks, but I have a lot of flickering while moving the sliders. is there a way to prevent flickering?

User avatar
Hellbent
Posts: 1194
Joined: 23 Sep 2017, 13:34

Re: A very nice Horizontal Slider.. How to make it vertical instead

Post by Hellbent » 18 Jan 2021, 17:17

No way to completely remove all flickering, I don't get much here on my end but it is very random.
One thing that can improve things is to change the gui background color to the same color as the sliders background
i.e. Gui, Color, % SomeColor

Other than that, if you have windows 8 or higher you can use a layered window and have 0 flickering.

This is an example of taking the slider and putting it in a Layered window and then taking the Layered window and setting another window as its parent so that it can sit inside the parent window like a normal control would. Unfortunately, that's only for windows 8+.

Requires The Layered Window Class Found here ------------> LAYERED WINDOW CLASS

Code: Select all

;***************************************************************************************************
#Include <My Altered Gdip Lib>  ;<------       Replace with your copy of GDIP
;***************************************************************************************************
#Include <LayeredWindow Class>
;***************************************************************************************************
#SingleInstance, Force
SetBatchLines, -1
OnExit, *ESC
width := 67, height := 400, SliderMin := 25, SliderMax := 50, SliderHeight := height - 60

;Gui 1 (Parent)
;****************************************************************
Gui, 1:+AlwaysOnTop -DPIScale +Toolwindow
Gui, 1:Color, 282D41
Gui, 1:Font, cWhite
Gui, 1:Add,CheckBox, x100 y40, Check Box
Gui, 1:Add,CheckBox, x100 y+30, Check Box
Gui, 1:Add,CheckBox, x100 y+30, Check Box
Gui, 1:Add,CheckBox, x100 y+30, Check Box
Gui, 1:Add, Button, x190 y350 w100 h40, Press Me!!!
Gui, 1:Show, % "w" 300 " h" height

; Gui 2 (Child)
;****************************************************************
New_Window := New LayeredWindow(x := 0 , y := 0 , w := width , h := height , window := 2 , title := " " , smoothing := 2 , options := "+Parent1 -DPIScale" , autoShow := 1 , GdipStart := 1 )
New_Window.Draw( DrawSliderVert( width, height ), { X: 0, Y: 0, W: width, H: height }, 1, 1)
New_Window.Add_Trigger( { X: 20, Y: 30, W: 27, H: SliderHeight }, "AdjustSliderVert")

return
GuiClose:
GuiContextMenu:
*ESC:: 
	New_Window.DeleteWindow( 1 )
	ExitApp
	
AdjustSliderVert:
	LastY := "", Value := 0
	CoordMode, Mouse, Client
	while(GetKeyState("LButton")){
		sleep, 30
		MouseGetPos, tx, ty
		If(ty=LastY)
			continue
		LastY := ty
		( ty <= 36 ) ? ( yPos := 30, Value := SliderMax ) : ( ty >= 364 ) ? ( yPos := 358, Value := SliderMin ) : ( yPos := ty - 6, Value := floor( ( ty - ( 30 + 6 ) ) / ( ( SliderHeight - 6 ) / ( SliderMax - SliderMin ) ) - SliderMax ) * -1 ) 
		New_Window.Draw( DrawSliderVert( width, height, ypos ), { X: 0, Y: 0, W: width, H: height }, 1, 1)
		ToolTip, % "Value: " Value 
	}
	ToolTip,
	return

DrawSliderVert( width, height, y := 309){
	;Bitmap Created Using: HB Bitmap Maker
	pBitmap:=Gdip_CreateBitmap( Width , Height ) , G := Gdip_GraphicsFromImage( pBitmap ), Gdip_SetSmoothingMode( G , 2 )
	; Background
	Brush := Gdip_BrushCreateSolid( "0xFF282D41" ), Gdip_FillRectangle( G , Brush , -1 , -1 , Width + 2 , Height + 2 ), Gdip_DeleteBrush( Brush )
	; Slider Track
	Brush := Gdip_BrushCreateSolid( "0xFF454C5F" ), Gdip_FillRectangle( G , Brush , 30 , 30 , 7 , 340 ), Gdip_DeleteBrush( Brush )
	; Slider Track Border
	Pen := Gdip_CreatePen( "0xFF222222" , 1 ), Gdip_DrawRectangle( G , Pen , 30 , 30 , 7 , 340 ), Gdip_DeletePen( Pen )
	;Button 
	Brush := Gdip_BrushCreateSolid( "0xFF2565B3" ), Gdip_FillRoundedRectangle( G , Brush , 20 , y , 27 , 12 , 3 ), Gdip_DeleteBrush( Brush )
	Pen := Gdip_CreatePen( "0xFF222222" , 1 ), Gdip_DrawRoundedRectangle( G , Pen , 20 , y , 27 , 12 , 3 ), Gdip_DeletePen( Pen )
	; Fill Guage
	Brush := Gdip_BrushCreateSolid( "0xFF2565B3" ), Gdip_FillRectangle( G , Brush , 31 , y , 5 , 370 - y ), Gdip_DeleteBrush( Brush )
	Gdip_DeleteGraphics( G )
	return pBitmap
}
20210118171531.png
20210118171531.png (9 KiB) Viewed 92 times

Besides all of that, you can just look at the difference between my first horz and vert sliders and make changes to your code to get the same type of outcome.

Post Reply

Return to “Ask For Help”