Slider changes progressbar length and reloads gui Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
blackjoker
Posts: 18
Joined: 01 Dec 2020, 02:57

Slider changes progressbar length and reloads gui

14 Jun 2021, 11:10

Hello,
maybe someone could help me.

I'm trying to create Slider which changes progressBar length (range) -> restarts GUI -> and to have progressbar with new parameter from slider. :arrow:
Is that possible? :?:
I tried to do that with global variables, but after reload it resets to default code and have no idea how to refresh GUI after slider changes. :problem:

Any ideas?

Code: Select all

global PBS_SMOOTH            := 0x00000001
global PBM_SETSTATE          := WM_USER + 16
global PBST_NORMAL           := 0x00000001

if (global Slider_length < 1)
{
	global Slider_length := 10
}

wScreen := 820
hScreen := 400

Gui, Add, GroupBox, % "xm+0 ym+0 w" (wScreen-140)  " h110 Section" , jobber
				
Gui, add, slider,% " xm+15 ym+30  w240 tooltip range1-" Slider_length " vSlider_length gSlider", % Slider_length

Gui, Add, Progress, % "xm+10 ym+70 w"(wScreen-160) "h15 hwndPROG -" PBS_SMOOTH " vJoinprogress range1-" Slider_length
DllCall("User32.dll\SendMessage", "Ptr", PROG, "Int", PBM_SETSTATE, "Ptr", PBST_NORMAL, "Ptr", 0)

	sek := 0
	Gui, Show

	settimer,label,1000

return

label:
	sek := sek + 1 
	if (sek > Slider_length+1){
		sek := 0
		MsgBox, do your job!
	}
	
	GuiControl,,Joinprogress, %sek%
return

slider:
	sek := 0
	Reload
	;~ Gui, Show
return

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Slider changes progressbar length and reloads gui

14 Jun 2021, 12:04

I don’t see why you need any variables declared as global. You have no functions which would have a different variable scope.

To keep the value of some variables, instead of using Reload, build the GUI in a subroutine, and call that subroutine each time you want to rebuild it, using Gui, Destroy at the beginning of that subroutine so you can build it from scratch each time.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Slider changes progressbar length and reloads gui  Topic is solved

14 Jun 2021, 12:17

To add to what Boiler said.

Depending on what you are doing there might not be any reason to recreate your gui. You can just update its range using GuiControl.

Code: Select all

#SingleInstance force

SliderValue := 100
SliderRange := 250

Gui, Add, Slider, xm ym w200 ToolTip Range1-%SliderRange% vSliderValue gChangeProgressRange, % SliderValue
Gui, Add, Progress, xm y+30 w200 cLime BackgroundRed Range1-%SliderValue% vProgressBar , 
Gui, Show
return
GuiClose:
	ExitApp

ChangeProgressRange:
	GuiControlGet, SliderValue
	GuiControl, +Range1-%SliderValue%, ProgressBar
	loop, % SliderValue	{
		GuiControl,, ProgressBar, % A_Index
		ToolTip, % A_Index
	}
	return

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

Re: Slider changes progressbar length and reloads gui

14 Jun 2021, 13:06

If it is a case where you do need to reload the script for w/e reason.
You can save your last values directly to the script like this (Non-Compiled scripts only)

Code: Select all

#SingleInstance force

/*
~~~~~~Saved Data~~~~~
[SliderData]
Value=100
Range=250
*/

IniRead, SliderValue, %A_ScriptFullPath%, SliderData, Value
IniRead, SliderRange, %A_ScriptFullPath%, SliderData, Range


Gui, Add, Text, xm ym w200 , % "( Slider Value / Progress Range ) " SliderValue
Gui, Add, Slider, xm w200 ToolTip Range1-%SliderRange% vSliderValue gChangeProgressRange, % SliderValue
Gui, Add, Progress, xm y+30 w200 cLime BackgroundRed Range0-%SliderValue% vProgressBar , 
Gui, Show

return
GuiClose:
	ExitApp

ChangeProgressRange:
	GuiControlGet, SliderValue
	GuiControl, +Range0-%SliderValue%, ProgressBar
	loop, % SliderValue	{
		GuiControl,, ProgressBar, % A_Index
		ToolTip, % A_Index
	}
	IniWrite, % SliderValue, %A_ScriptFullPath%, SliderData, Value
	time := 3
	loop, 3	{
		toolTip, % "Reloading script in " Time--
		sleep, 1000
	}
	Reload
	return

User avatar
blackjoker
Posts: 18
Joined: 01 Dec 2020, 02:57

Re: Slider changes progressbar length and reloads gui

15 Jun 2021, 09:38

Thank you Hellbent and boiler for help, i really apreciate that! And you totally solved my problem! :superhappy:

Here is final code after your help :clap: :

Code: Select all

global PBS_SMOOTH            := 0x00000001
global PBM_SETSTATE          := WM_USER + 16
global PBST_NORMAL           := 0x00000001

if (global Slider_length < 1)
{
	global Slider_length := 20
}

wScreen := 820
hScreen := 400

Gui, Add, GroupBox, % "xm+0 ym+0 w" (wScreen-140)  " h110 Section" , jobber

	Gui, add, slider,% " xm+15 ym+30  w240 tooltip range1-60 vSlider_length gSlider", % Slider_length

	Gui, Add, Progress, % "xm+10 ym+70 w"(wScreen-160) "h15 hwndPROG -" PBS_SMOOTH " vJoinprogress range0-" Slider_length
	DllCall("User32.dll\SendMessage", "Ptr", PROG, "Int", PBM_SETSTATE, "Ptr", PBST_NORMAL, "Ptr", 0)

	sek := 0
	Gui, Show

	settimer,label,1000

return

label:
	sek := sek + 1 
	if (sek > Slider_length){
		sek := 0
		MsgBox, do your job!
	}
	
	GuiControl,,Joinprogress, %sek%
return

slider:
	sek := 0
	GuiControlGet, Slider_length
	GuiControl, +Range0-%Slider_length%, Joinprogress
	GuiControl,, Joinprogress, 0
return



Spoiler

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, mikeyww, RandomBoy, wpulford and 381 guests