Minimizing windows on the minor under the mouse Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TheBeginner
Posts: 91
Joined: 19 Oct 2018, 12:05

Minimizing windows on the minor under the mouse

19 Oct 2018, 12:59

I tried to create a script that minimizes all windows in the monitor under the mouse, unfortunately I can't make it work it just minimizes all windows
and I can't seem to find the problem, any help will be appreciated

Code: Select all


^d::
CoordMode, Mouse, Screen
MouseGetPos, x, y
SysGet, Mon2, Monitor, 1
Mon1 := Mon2Right - Mon2Left
SysGet, Mon2, Monitor, 2
Mon2 := Mon2Right


WinGet, id, List,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
	WinGetPos, wgp_x, wgp_y,,, ahk_id %this_id%
	;WinGetTitle, this_title, ahk_id %this_id%
    
    if (wgp_x >= 0 and x >= Mon1 )  {
    
        WinMinimize ahk_id %this_id%
	
    } 
}
return

User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Minimizing windows on the minor under the mouse

19 Oct 2018, 13:16

Code: Select all

#SingleInstance, Force

^d:: ; Single Window
	CoordMode, Mouse, Screen
	MouseGetPos, MouseX, MouseY, MouseWin, MouseCtl
	WinMinimize, ahk_id %MouseWin%
return

Code: Select all

#SingleInstance, Force

^d:: ; All windows
	Loop {
		CoordMode, Mouse, Screen
		MouseGetPos, MouseX, MouseY, MouseWin, MouseCtl
		
		WinGetTitle, WinTitle, ahk_id %MouseWin%
		WinGetClass, WinClass, ahk_id %MouseWin%
		
		If ((WinTitle = "Program Manager")
		&& (WinClass = "Progman"))
		|| (WinClass = "Shell_TrayWnd") {
			Break
		}
		
		WinMinimize, ahk_id %MouseWin%
	}
return
TheBeginner
Posts: 91
Joined: 19 Oct 2018, 12:05

Re: Minimizing windows on the minor under the mouse

19 Oct 2018, 14:37

Thanks for posting a reply, I went through the script it took me a while to understand exactly what it does. I was trying to do something else, I wanted to minimize all windows in the monitor where the mouse is.
This script minimizes all windows underneath the mouse, which is cool, but not what I was trying to do. (minimize all windows in the monitor where the mouse is)

Any idea how I can achieve that?
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Minimizing windows on the minor under the mouse  Topic is solved

19 Oct 2018, 15:38

I only had 2 monitors (Left [Primary] & Right [Secondary]) to test this. Hope it works!

Code: Select all

#SingleInstance, Force
CoordMode, Mouse, Screen

F1::
	MouseGetPos, MouseX, MouseY, MouseWin, MouseCtl

	MouseMon := GetMonitorAt(MouseX, MouseY)

	WinGet, List, List,,, Program Manager

	Loop, % List {
		this_id := List%A_Index%

		If (GetMonitorIndexFromWindow(this_id) = MouseMon) {
			WinMinimize, ahk_id %this_id%
		}
	}
return

GetMonitorAt(X, Y, Default := 1){
	SysGet, MonCount, MonitorCount

	Loop, % MonCount {
		SysGet, Mon, Monitor, % A_Index

		If (X >= MonLeft && X <= MonRight && Y >= MonTop && Y <= MonBottom) {
			return A_Index
		}
    }

    return Default
}

GetMonitorIndexFromWindow(windowHandle) {
	; Starts with 1.
	monitorIndex := 1

	VarSetCapacity(monitorInfo, 40)
	NumPut(40, monitorInfo)

	if (monitorHandle := DllCall("MonitorFromWindow", "uint", windowHandle, "uint", 0x2))
		&& DllCall("GetMonitorInfo", "uint", monitorHandle, "uint", &monitorInfo)
	{
		monitorLeft   := NumGet(monitorInfo,  4, "Int")
		monitorTop    := NumGet(monitorInfo,  8, "Int")
		monitorRight  := NumGet(monitorInfo, 12, "Int")
		monitorBottom := NumGet(monitorInfo, 16, "Int")
		workLeft      := NumGet(monitorInfo, 20, "Int")
		workTop       := NumGet(monitorInfo, 24, "Int")
		workRight     := NumGet(monitorInfo, 28, "Int")
		workBottom    := NumGet(monitorInfo, 32, "Int")
		isPrimary     := NumGet(monitorInfo, 36, "Int") & 1

		SysGet, monitorCount, MonitorCount

		Loop, %monitorCount%
		{
			SysGet, tempMon, Monitor, %A_Index%

			; Compare location to determine the monitor index.
			if ((monitorLeft = tempMonLeft) and (monitorTop = tempMonTop)
				and (monitorRight = tempMonRight) and (monitorBottom = tempMonBottom))
			{
				monitorIndex := A_Index
				break
			}
		}
	}

	return monitorIndex
}
TheBeginner
Posts: 91
Joined: 19 Oct 2018, 12:05

Re: Minimizing windows on the minor under the mouse

20 Oct 2018, 11:15

It definitely works, But I don't get why.
The entire "GetMonitorIndexFromWindow" function why is it necessary? What does it do?
all the NumGet
TheBeginner
Posts: 91
Joined: 19 Oct 2018, 12:05

Re: Minimizing windows on the minor under the mouse

20 Oct 2018, 16:12

Worked on it for hours, finally succeeded. the script was an awesome starting point, Still don't know what all these "NumGet" are.
thanks for all your great help!!

Code: Select all

if (monitorHandle := DllCall("MonitorFromWindow", "uint", windowHandle, "uint", 0x2))
		&& DllCall("GetMonitorInfo", "uint", monitorHandle, "uint", &monitorInfo)
	{
		monitorLeft   := NumGet(monitorInfo,  4, "Int")
		monitorTop    := NumGet(monitorInfo,  8, "Int")
		monitorRight  := NumGet(monitorInfo, 12, "Int")
		monitorBottom := NumGet(monitorInfo, 16, "Int")
		workLeft      := NumGet(monitorInfo, 20, "Int")
		workTop       := NumGet(monitorInfo, 24, "Int")
		workRight     := NumGet(monitorInfo, 28, "Int")
		workBottom    := NumGet(monitorInfo, 32, "Int")
		isPrimary     := NumGet(monitorInfo, 36, "Int") & 1

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: haomingchen1998, mikeyww, mmflume, OrangeCat, roysubs, scriptor2016, ShatterCoder and 100 guests