GuiShow() with MonitorN option supported

Post your working scripts, libraries and tools
tmplinshi
Posts: 1599
Joined: 01 Oct 2013, 14:57

GuiShow() with MonitorN option supported

10 Sep 2020, 08:45

Code: Select all

; GuiShow("w400 h400 Monitor2")
GuiShow(Options := "", Title := "", GuiName := 1)
{
	SysGet, mCount, MonitorCount
	SysGet, mPrimary, MonitorPrimary

	if RegExMatch(Options, "i)Monitor\K\d+", mNumber)
		Options := StrReplace(Options, "Monitor" mNumber)

	if !mNumber || (mCount = 1) || (mNumber = mPrimary) {
		Gui, %GuiName%:Show, % Options, % Title
		Return
	}
	
	SysGet, m, MonitorWorkArea, %mNumber%

	if optX := RegExMatch(Options, "i)\bx\K\d+\b", x)
		Options := RegExReplace(Options, "\bx\K\d+\b", x+mLeft)
	if !(optY := RegExMatch(Options, "i)\by\d+\b")) || !optX
	{
		Gui, %GuiName%:+HWNDhWnd
		Gui, %GuiName%:Show, %Options% Hide NA

		dhw := A_DetectHiddenWindows
		DetectHiddenWindows, On
		WinGetPos,,, guiW, guiH, ahk_id %hwnd%
		DetectHiddenWindows, %dhw%

		if !optX
			Options .= " x" Round(mLeft + (mRight-mLeft)/2 - guiW/2)
		if !optY
			Options .= " y" Round(mTop + (mBottom-mTop)/2 - guiH/2)
	}

	Gui, %GuiName%:Show, % Options, % Title
}
User avatar
Tigerlily
Posts: 359
Joined: 04 Oct 2018, 22:31

Re: GuiShow() with MonitorN option supported

10 Sep 2020, 11:33

@tmplinshi

Is the purpose of this script to make the GUI show up in a specified monitor screen instead of the default primary screen?
-TL
User avatar
elModo7
Posts: 189
Joined: 01 Sep 2017, 02:38
GitHub: elModo7
Location: Spain
Contact:

Re: GuiShow() with MonitorN option supported

12 Sep 2020, 14:34

Quite useful for some of my uses, thanks!
:beer:

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Bing [Bot] and 15 guests