Script crashes when i click on my gui

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xInDiGo
Posts: 2
Joined: 03 Jul 2019, 19:01

Script crashes when i click on my gui

Post by xInDiGo » 04 Oct 2022, 23:05

So i'm trying to make a gui parent window with controls. the parent gui also opens up nvidia control panel in the parent window. This works, until i try to click on the control. Then the script will crash & windows will ask me to terminate. i don't get any error messages when it crashes. Any ideas would be of great help.

here is my source code in case anybody can help;

Code: Select all

#SingleInstance force

Gui, Show, w1285 h1023, nVidia Control Panel Buddy
Gui, +LastFound
GuiWindow := WinExist()

loop{
	ifWinExist, NVIDIA Control Panel
	{
		ControlWindow := WinExist("NVIDIA Control Panel")
		break
	}
	else
	{
		Run, nvcplui.exe,,minimized
		sleep 1000
		continue
	}
}

DllCall("SetParent", "uint", ControlWindow, "uint", GuiWindow)
DllCall("SetWindowPos", "uint", ControlWindow, "uint", 0
    , "int", 10, "int", 10, "int", 1042, "int", 705
    , "uint", SWP_SHOWWINDOW|SWP_NOSENDCHANGING)

WinSet, Style, 0x800000, A
Gui, Add, GroupBox, xm+1050 ym w160 h210 , --Custom Settings--
Gui, Add, Text, xp+25 yp+20 w50 h25 , Brightness
Gui, Add, Edit, xp+60 yp-3 w50 h20 Number ReadOnly vBrightnessDisplay, %BrightnessValue%
Gui, Add, Text, xp-60 yp+45 w50 h25 , Contrast
Gui, Add, Edit, xp+60 yp-5 w50 h20 Number ReadOnly vContrastDisplay, %ContrastValue%
Gui, Add, Text, xp-60 yp+45 w50 h25 , Gamma
Gui, Add, Edit, xp+60 yp-5 w50 h20 Number ReadOnly vGammaDisplay, %GammaValue%
Gui, Add, Text, xp-60 yp+45 w50 h25 , Vibrance
Gui, Add, Edit, xp+60 yp-5 w50 h20 Number ReadOnly vVibranceDisplay, %VibranceValue%
Gui, Add, Text, xp-60 yp+45 w50 h25 , Hue
Gui, Add, Edit, xp+60 yp-5 w50 h20 Number ReadOnly vHueDisplay, %HueValue%
Gui, Add, GroupBox, xm+1050 ym+220 w160 h80 , --Settings Control--
Gui, Add, Button, xp+5 yp+20 w75 h30 gSave, Save
Gui, Add, Button, xp+75 yp w75 h30 gSaveDefault, Save Default
Gui, Add, CheckBox, xp-75 yp+35 vAutoAdjust gMonitorActiveWindow, Automatically adjust settings
WinHide, A
WinShow, A


loop{
	if WinActive("NVIDIA Control Panel"){
		UpdateData()
		continue
	}
	else
		Working()
		continue
}


return

MonitorActiveWindow:
msgbox Monitor Active
return

Save:
Gui, Submit
SaveValues()
reload

SaveDefault:
Gui, Submit
SaveDefaultValues()
reload

GuiClose:
ExitApp

Esc::
ExitApp

Working(){
	While WinExist("EscapeFromTarkov")
	{
		If !GetKeyState("Alt")
		{
			IfWinActive, EscapeFromTarkov
			{
				Loop{
					BrightnessAdjust(validateFN(BrightnessValue))
					sleep 100
					ContrastAdjust(validateFN(ContrastValue))
					sleep 100
					GammaAdjust(validateFN(GammaValue))
					sleep 100
					VibranceAdjust(validateFN(VibranceValue))
					sleep 100
					HueAdjust(validateFN(HueValue))
					sleep 100
					break
				}
			}
		}
		else
		{
			Loop
			{
				BrightnessAdjust(validateFN(%DefaultBrightnessValue%))
				sleep 100
				ContrastAdjust(validateFN(DefaultContrastValue))
				sleep 100
				GammaAdjust(validateFN(DefaultGammaValue))
				sleep 100
				VibranceAdjust(validateFN(DefaultVibranceValue))
				sleep 100
				HueAdjust(validateFN(DefaultHueValue))
				sleep 100
				break
			}
		}
	}
}

SaveValues(){
	global
	IniWrite, %BrightnessValue%, visualsettings.ini, BrightnessDisplay, Value
	IniWrite, %ContrastValue%, visualsettings.ini, ContrastDisplay, Value
	IniWrite, %GammaValue%, visualsettings.ini, GammaDisplay, Value
	IniWrite, %VibranceValue%, visualsettings.ini, VibranceDisplay, Value
	IniWrite, %HueValue%, visualsettings.ini, HueDisplay, Value
}

SaveDefaultValues(){
	global
	IniWrite, BrightnessValue, visualsettings.ini, DefaultBrightnessDisplay, Value
	IniWrite, %ContrastValue%, visualsettings.ini, DefaultContrastDisplay, Value
	IniWrite, %GammaValue%, visualsettings.ini, DefaultGammaDisplay, Value
	IniWrite, %VibranceValue%, visualsettings.ini, DefaultVibranceDisplay, Value
	IniWrite, %HueValue%, visualsettings.ini, DefaultHueDisplay, Value
}

UpdateData(){
	global
	ControlGetText, BrightnessValue, static27, nVidia Control Panel Buddy
	GuiControl,, BrightnessDisplay, %BrightnessValue%

	ControlGetText, ContrastValue, static32, nVidia Control Panel Buddy
	GuiControl,, ContrastDisplay, %ContrastValue%

	ControlGetText, GammaValue, static37, nVidia Control Panel Buddy
	GuiControl,, GammaDisplay, %GammaValue%

	ControlGetText, VibranceValue, static43, nVidia Control Panel Buddy
	GuiControl,, VibranceDisplay, %VibranceValue%

	ControlGetText, HueValue, static53, nVidia Control Panel Buddy
	GuiControl,, HueDisplay, %HueValue%
	return
}

BrightnessAdjust(MyBValue=""){
	Loop{
		ControlGetText, BValue, static27, NVIDIA Control Panel
		if (validateFN(BValue) > MyBValue){
			;ToolTip, Brightness Value: %MyBValue%, MyMouseX(), MyMouseY()
			ControlSend, msctls_trackbar321, {Left}, NVIDIA Control Panel
		}
		else if (validateFN(BValue) < MyBValue){
			;ToolTip, Brightness Value: %MyBValue%, MyMouseX(), MyMouseY()
			ControlSend, msctls_trackbar321, {Right}, NVIDIA Control Panel
		}
		else if (validateFN(BValue) = MyBValue){
			break
		}
	}
}

ContrastAdjust(MyCValue=""){
	Loop{
		ControlGetText, CValue, static32, NVIDIA Control Panel
		if (validateFN(CValue) > MyCValue){
			;ToolTip, Contrast Value: %MyCValue%, MyMouseX(), MyMouseY()
			ControlSend, msctls_trackbar322, {Left}, NVIDIA Control Panel
		}
		else if (validateFN(CValue) < MyCValue){
			;ToolTip, Contrast Value: %MyCValue%, MyMouseX(), MyMouseY()
			ControlSend, msctls_trackbar322, {Right}, NVIDIA Control Panel
		}
		else if (validateFN(CValue) = MyCValue){
			break
		}
	}
}


GammaAdjust(MyGValue=""){
	Loop{
		ControlGetText, GValue, static37, NVIDIA Control Panel
		;ToolTip, Gamma Value: %GValue%, MyMouseX(), MyMouseY()
		if (validateFN(GValue) > MyGValue){
			;ToolTip, Gamma Value: %MyGValue%, MyMouseX(), MyMouseY()
			ControlSend, msctls_trackbar323, {Left}, NVIDIA Control Panel
		}
		else if (validateFN(GValue) < MyGValue){
			;ToolTip, Gamma Value: %MyGValue%, MyMouseX(), MyMouseY()
			ControlSend, msctls_trackbar323, {Right}, NVIDIA Control Panel
		}
		else if (validateFN(GValue) = MyGValue){
			break
		}
	}
}


VibranceAdjust(MyVValue=""){
	Loop{
		ControlGetText, VValue, static43, NVIDIA Control Panel
		if (validateFN(VValue) > MyVValue){
			;ToolTip, Vibrance Value: %MyVValue%, MyMouseX(), MyMouseY()
			ControlSend, msctls_trackbar324, {Left}, NVIDIA Control Panel
		}
		else if (validateFN(VValue) < MyVValue){
			;ToolTip, Vibrance Value: %MyVValue%, MyMouseX(), MyMouseY()
			ControlSend, msctls_trackbar324, {Right}, NVIDIA Control Panel
		}
		else if (validateFN(VValue) = MyVValue){
			break
		}
	}
}

HueAdjust(MyHValue=""){
	Loop{
		ControlGetText, HValue, Static53, NVIDIA Control Panel
		if (validateFN(HValue) > MyHValue){
			;ToolTip, Contrast Value: %MyCValue%, MyMouseX(), MyMouseY()
			ControlSend, msctls_trackbar326, {Left}, NVIDIA Control Panel
		}
		else if (validateFN(HValue) < MyHValue){
			;ToolTip, Contrast Value: %MyCValue%, MyMouseX(), MyMouseY()
			ControlSend, msctls_trackbar326, {Right}, NVIDIA Control Panel
		}
		else if (validateFN(CValue) = MyHValue){
			break
		}
	}
}

validateFN(FN) {
  chars:="\/:*?<>|%°" chr(34) A_Space
  loop, parse, chars
    FN := strReplace(FN, A_loopfield, "")
  return % FN
}

Return to “Ask for Help (v1)”