 
 
 
-;More Frontend functions
-GetPresetPropWidth(PresetPropHwnd)
-{
-GuiControlGet, temp, PrgLnch: Pos, %PresetPropHwnd%
+;More Frontend functions for Batch and controls
+GetPresetPropWidth(PresetPropHWnd)
+{
+GuiControlGet, temp, PrgLnch: Pos, %PresetPropHWnd%
 return floor(tempw * 1.3)
 }
 
-LnchLnchPad(SelIniChoiceName)
-{
-static ERROR_FILE_NOT_FOUND := 0x2, ERROR_ACCESS_DENIED := 0x5, ERROR_CANCELLED := 0x4C7
-strTemp := ""
-
-PrgPropertiesClose()
-
-Gui, PrgLnch: +Disabled
-
-strRetVal := WorkingDirectory(A_ScriptDir, 1)
-
-
-	if (strRetVal)
-	{
-	MsgBox, 8192, Script Directory, % strRetVal "`nCannot load LnchPad file!"
-	strTemp := "Bad Directory"
-	}
-	else
-	{
-	strTemp2 := A_ScriptDir . "\LnchPadInit.exe"
-		if (FileExist(strTemp2))
-		{
-		; no version checking, however this is good enough
-			if (!SelIniChoiceName)
-			FileInstall LnchPadInit.exe, LnchPadInit.exe, 1
-		}
-		else
-		{
-		FileInstall LnchPadInit.exe, LnchPadInit.exe
-		UnBlockFile(strTemp2)
-		}
-
-		if (!A_IsAdmin)
-		{
-		retVal := TaskDialog("LnchPad Setup Elevated", "Admin is required for full functionality", , "", "", "Restart LnchPad Setup as Admin", "Try it without Admin")
-			if (retVal == 1)
-			strTemp2 := "*runAs " . strTemp2
-		SplashyProc("*LnchPadCfg")
-		}
-
-	CurrResStore(PrgLnch.Monitor, -1)
-	strTemp := PrgLnchOpt.scrWidth . "," . PrgLnchOpt.scrHeight . "," . PrgLnchOpt.scrFreq . "," . 0
-
-	Run, %strTemp2% %strTemp% %SelIniChoiceName%, , UseErrorLevel, OutputVarPID
-	strTemp := ""
-
-		if (A_LastError)
-		{
-			Switch, A_LastError
-			{
-			Case 0x2:
-			strTemp := ERROR_FILE_NOT_FOUND
-			Case 0x5:
-			strTemp := ERROR_ACCESS_DENIED
-			Case 0x4C7:
-			strTemp := ERROR_CANCELLED
-			}
-		strTemp := "LnchPadInit will not run. Code: " (strTemp? strTemp: A_LastError)
-		}
-		else
-		{
-			if (OutputVarPID)
-			WinWait, ahk_pid %OutputVarPID%, , 10
-			else
-			{
-				if (!strTemp)
-				strTemp := "Unknown Error"
-			}
-
-		PrgLnch.LnchPadPID := OutputVarPID
-		}
-	}
-
-Gui, PrgLnch: -Disabled
-DetectHiddenWindows, On
-
-PrgLnch.Activate()
-
-DetectHiddenWindows, Off
-return strTemp
-}
-
-HideShowLnchControls(quitHwnd, GoConfigHwnd, showCtl := 0)
+HideShowLnchControls(quitHWnd, GoConfigHWnd, showCtl := 0)
 {
 if (showCtl)
 	{

	gui, NonStockResDlg: Destroy
	return 0
}

DisplayActiveWindowProps(indexIn, prgPIDIn := 0)
{
static WS_EX_CONTEXTHELP := 0x00000400
static AWPPrgPriority
Global AWPPrgMinMax1 := 0, AWPPrgMinMax2 := 0, AWPPrgMinMax3 := 0, AWPPrgMinMax4 := 0, AWPPrgMinMax5 := 0, AWPPrgMinMax6 := 0, AWPPrgMinMax7 := 0, AWPPrgMinMax8 := 0, AWPPrgMinMax9 := 0, AWPPrgMinMax10, AWPPrgMinMax11 := 0, AWPPrgMinMax12 := 0
Global AWPBordless1 := 0, AWPBordless2 := 0, AWPBordless3 := 0, AWPBordless4 := 0, AWPBordless5 := 0, AWPBordless6 := 0, AWPBordless7 := 0, AWPBordless8 := 0, AWPBordless9 := 0, AWPBordless10 := 0, AWPBordless11 := 0, AWPBordless12 := 0
static selPrgChoice := 0, windowHandlesNo := 1
temp := 0, strTemp := "", visibleWindowHandlesNo := 0, prgPID := 0
static winNames := ["", "", "", "", "", "", "", "", "", "", "", ""]

	if (prgPIDIn)
	selPrgChoice := indexIn
	else
	{
		loop, Parse, % PrgLnchOpt.ListPrgStr, CSV
		{
			if (A_Index == indexIn && strTemp := A_Loopfield)
			{
				loop % PrgLnchOpt.PrgNo
				{
					if (strTemp == PrgLnchOpt.GetPrgChoiceNames(A_Index))
					{
					temp := A_Index
					break
					}
				}

				if (temp == A_Index)
				break
			}
		}

		if (temp)
		selPrgChoice := temp
		else
		{
		MsgBox, 8192, DisplayActiveWindowProps, % "Unexpected error with " . PrgLnchOpt.ListPrgStr(indexIn) . "!"
		return 0
		}
	}

	Loop % PrgLnchOpt.PrgNo ; iterate through active windows of prg
	{
		if (temp := PrgLnchOpt.GetTestWindowHandles(selPrgChoice, A_Index))
		{
		windowHandlesNo := A_Index
		; Hidden windows will be blank.
		WinGetTitle, strTemp, ahk_id %temp%
		winNames[A_Index] := strTemp
			if (strTemp)
			visibleWindowHandlesNo++
		}
		else
		{
			if (!prgPIDIn)
			{
			WinGet, prgPID, PID, % "ahk_id" . PrgLnchOpt.GetTestWindowHandles(selPrgChoice, 1)
				if (!PrgPID)
				{
				MsgBox, 8192, Display Active Window, Cannot find the Prg PID!
				return 0
				}
			}

			if (!visibleWindowHandlesNo)
			{
			MsgBox, 8192, Display Active Window, Could not find window handle!
			return 0
			}
		break
		}
	}

	if (prgPIDIn)
	{
		if (visibleWindowHandlesNo < 2)
		return 1
	prgPID := prgPIDIn
	}

height := A_ScreenHeight/5, numWMIResolutionmodesTmp := 0

gui, ActiveWindowProp: -MaximizeBox -MinimizeBox +E%WS_EX_CONTEXTHELP% +OwnerPrgLnch HWNDhWndActiveWindowProp

Gui, PrgLnch: +Disabled

gui, ActiveWindowProp: Add, Checkbox, section w%height% vAWPPrgPriority gAWPPrgPriorityChk HWNDAWPPrgPriorityHwnd Check3, Prg Priority (BN-N-H)
;check3 enables 3 values in checkbox
GuiControl, ActiveWindowProp: Enable, AWPPrgPriority
GuiControl, ActiveWindowProp:, AWPPrgPriority, % PrgLnchOpt.GetPrgRnPriority(selPrgChoice)


gui, ActiveWindowProp: Font, cA96915 Bold
gui, ActiveWindowProp: add, text, % "section w" . 2.4*height, % "Windows of " PrgLnchOpt.GetPrgChoiceNames(selPrgChoice)


Gui, ActiveWindowProp: Font


Gui, ActiveWindowProp: Add, Groupbox, % "section" . " w" . 2.4*height . " R" . 2*visibleWindowHandlesNo

	loop %windowHandlesNo%
	{
		; Hidden windows are not considered
		if (winNames[A_Index])
		{
		Gui, ActiveWindowProp: Font, cA96915 Bold S8
		Gui, ActiveWindowProp: Add, text, % "xs+" . height/8 . " yp+" . height/10 . " w" . height, % winNames[A_Index]
		Gui, ActiveWindowProp: Font
		Gui, ActiveWindowProp: Add, Checkbox, % "xs+" . height/8 . " yp+" . height/8 . " w" . height . " vAWPPrgMinMax" . A_Index . " gAWPClick Check3", Min-Norm-Max
		GuiControl, ActiveWindowProp: Enable, % "AWPPrgMinMax" . A_Index
		WinGet, fTemp, MinMax , % "ahk_id" . PrgLnchOpt.GetTestWindowHandles(selPrgChoice, A_Index)
			if (fTemp == -1 )
			fTemp := 0
			else
			{
				if (!fTemp)
				fTemp := -1
			}
		

		GuiControl, ActiveWindowProp:, % "AWPPrgMinMax" . A_Index, %fTemp%
		Gui, ActiveWindowProp: Add, Checkbox, % "xp+" . height . " yp wp vAWPBordless" . A_Index . " gAWPClick", Borderless

			; not available if lnk or alien IMAGE_SUBSYSTEM etc.
			if (PrgLnchOpt.borderToggle)
			GuiControl, ActiveWindowProp: Enable, AWPBordless
		}
	}

Gui, ActiveWindowProp: Font


gui, ActiveWindowProp: show, % "hide x" . height "w" . 2.5*height, Active Window Properties

WinMover(hWndActiveWindowProp, "d r")

gui, ActiveWindowProp: show
;WinWaitClose, ahk_id %hWndActiveWindowProp%
return 0

AWPPrgPriorityChk:
Gui, ActiveWindowProp: Submit, Nohide

PrgLnchOpt.SetPrgRnPriority(selPrgChoice, AWPPrgPriority)
IniProc(selPrgChoice)

(!AWPPrgPriority)? temp := "B": (PrgPriority == 1)? temp := "H": temp := "N"
Process, priority, %PrgPID%, % temp

return 0

AWPClick:
Gui, ActiveWindowProp: Submit, Nohide

clickedindex := 0
	loop % windowHandlesNo
	{
		if (InStr(A_GuiControl, windowHandlesNo - A_Index + 1))
		{
		clickedindex := windowHandlesNo - A_Index + 1
		break
		}
	}
hWnd := PrgLnchOpt.GetTestWindowHandles(selPrgChoice, clickedindex)
GuiControlGet, temp, ActiveWindowProp: , % A_GuiControl

	if (InStr(A_GuiControl, "PrgMinMax"))
	{
	WinGet, fTemp, MinMax , % "ahk_id" . PrgLnchOpt.GetTestWindowHandles(selPrgChoice, clickedindex)
	; make it consistent with the switch statement below
		if (fTemp == -1 )
		fTemp := 0
		else
		{
			if (!fTemp)
			fTemp := -1
		}

	lTemp := temp

	; What if user max/min/restores it?
		if (fTemp == -1 )
		{
			if (temp)
			{
			temp := 0
			}
		}

		else
		{
			if (fTemp)
			{
				if (temp != -1)
				{
				temp := -1
				}
			}
			else
			{
				if (temp != 1)
				{
				temp := 1
				}
			}

		}



		if (lTemp != temp)
		GuiControl, ActiveWindowProp:, % "AWPPrgMinMax" . clickedindex, %temp%


		; assume the prg is launched as 
		switch (temp)
		{
		case -1:
		WinRestore, ahk_id %hWnd%
		case 0:
		WinMinimize, ahk_id %hWnd%
		case 1:
		{
		WinMaximize, ahk_id %hWnd%
		sleep 20
			if (PrgLnchOpt.GetPrgMonToRn(selPrgChoice) == Prglnch.Monitor)
			WinActivate, % "ahk_id" PrgLnch.Hwnd()
		;WinActivate, ahk_id %hWndActiveWindowProp%
		}
		}
	}
	else
	{
		if (!InStr(A_GuiControl, "Bordless"))
		return 0 ; just in case
	BordlessProc(0, selPrgChoice, clickedindex, hWnd)
	}	


;PrgLnchOpt.GetPrgMinMax(selPrgChoice, clickedindex)
;PrgLnchOpt.GetPrgWindowStyles(selPrgChoice, clickedindex)
return 0

AWPQuit:
ActiveWindowPropGuiClose:
ActiveWindowPropGuiEscape:
gui, ActiveWindowProp: Destroy
Gui, PrgLnch: -Disabled
WinActivate, % "ahk_id" PrgLnch.Hwnd()
return 0
}


SortSourceModes(dispMonIn, numWMIResolutionmodes, ResArray)
{

sleep, 120

Gui, PrgProperties: New,, Prg_Properties
Gui, PrgProperties: -MaximizeBox -MinimizeBox +OwnDialogs +HWndPrgPropertiesHWnd
; PrgProperties.HWnd in this thread isn't valid while the form is hidden unofrtunately
PrgProperties.HWnd := PrgPropertiesHWnd
Gui, PrgProperties: Color, FFFFCC


