AMM
AMM

Reputation: 135

How do I use AutoHotKey to expand window across dual monitors with Win 7 taskbar on left?

Credit to @Jeff Axelrod for the solution I need a modification to. I cannot figure out how to alter this so that it "respects" the windows taskbar I keep on the left side of my left monitor. I have a number of custom toolbars in my Win 7 taskbar and so it's a couple inches wide. The code below maximizes the current window across both monitors, but a portion of that expanded window is therefore underneath my taskbar.

+#Up::
WinGetActiveTitle, Title
WinRestore, %Title%
SysGet, X1, 76
SysGet, Y1, 77
SysGet, Width, 78
SysGet, Height, 79
WinMove, %Title%,, X1, Y1, Width, Height
return

I'm sure I'm missing something simple here but it's been one of those days :-)

Here's a screenshot which shows how the window is underneath my taskbar. Please refer to the upper left corner where it is most obvious that the maximized window is underneath:

screenshot of window "not respecting" taskbar

Upvotes: 0

Views: 2050

Answers (1)

Elliot DeNolf
Elliot DeNolf

Reputation: 2999

You are looking for the MonitorWorkArea, namely the MonitorWorkAreaLeft by the looks of your screenshot.

Script to get all monitor info:

SysGet, MonitorCount, MonitorCount
SysGet, MonitorPrimary, MonitorPrimary
Message .= "Monitor Count:`t" MonitorCount "`nPrimary Monitor:`t" MonitorPrimary
Loop, %MonitorCount%
{
    SysGet, MonitorName, MonitorName, %A_Index%
    SysGet, Monitor, Monitor, %A_Index%
    SysGet, MonitorWorkArea, MonitorWorkArea, %A_Index%
    Message .= "`n`nMonitor:`t#" A_Index "`nName:`t" MonitorName "`nLeft:`t" MonitorLeft "(" MonitorWorkAreaLeft " work)`nTop:`t" MonitorTop " (" MonitorWorkAreaTop " work)`nRight:`t" MonitorRight " (" MonitorWorkAreaRight " work)`nBottom:`t" MonitorBottom "(" MonitorWorkAreaBottom " work)"
}

msgbox % Message

Once you find the correct monitor you would like to use, use the value for coordinates:

SysGet, MonitorWorkArea, MonitorWorkArea, 2
msgbox % MonitorWorkAreaLeft

EDIT

This will grab the values and move the window each time you run it.

SysGet, MonitorWorkArea, MonitorWorkArea, 1 ; Leftmost monitor
X1 := MonitorWorkAreaLeft
Y1 := MonitorWorkAreaTop
SysGet, MonitorWorkArea, MonitorWorkArea, 2 ; Rightmost monitor
Width := MonitorWorkAreaRight - X1
Height := MonitorWorkAreaBottom

WinGetActiveTitle, Title
WinMove, % Title,, % X1, % Y1, % Width, % Height

Upvotes: 1

Related Questions