AutoHotKey:Windows 10 上的奇怪窗口大小调整行为

AutoHotKey:Windows 10 上的奇怪窗口大小调整行为

我意识到这可能是一个非常模糊的问题,但嘿,这是互联网。

我有一台 24 英寸的纵向显示器,我想垂直对齐。我找到了一个在线脚本,但对于大多数类型的窗口,将其大小设置为显示器分辨率的精确尺寸会导致它们略微太小。Chrome、Edge 甚至记事本都会出现这种情况。但是,Telegram 窗口的行为符合预期。

调试 AHK 脚本显示,当 Edge 在 1200x1920 显示器上最大化时,其尺寸实际上是 1216x1896(考虑到开始菜单,垂直尺寸较小,但仍然比应有的高度高)。

我已仔细检查了 Windows 显示缩放设置,它确实设置为 100%。

有人知道这里发生了什么事吗?

目前,我必须通过进行各种检查并将不同的方法分配给不同的热键来解决这个问题。

; dir 0 = top part
; dir 1 = bottom part
; method 0 = funky
; method 1 = exact

ResizeWin(dir = 1, method = 0)
{
    WinGet activeWin, ID, A
    activeMon := GetMonitorIndexFromWindow(activeWin)

    SysGet, MonitorWorkArea, MonitorWorkArea, %activeMon%

    if (method == 0) {
        WinMaximize, A
        WinGetPos, CurWinX, CurWinY, CurWinWidth, CurWinHeight, A
        newWidth := CurWinWidth
        newHeight := CurWinHeight/2
        newLeft := CurWinX

        if (dir == 1)
            newTop := MonitorWorkAreaTop + newHeight + (CurWinY - MonitorWorkAreaTop)
        else
            newTop := MonitorWorkAreaTop
    } else {

        newWidth := MonitorWorkAreaRight - MonitorWorkAreaLeft
        newHeight := (MonitorWorkAreaBottom - MonitorWorkAreaTop)/2
        newLeft := MonitorWorkAreaLeft

        if (dir == 1)
            newTop := MonitorWorkAreaBottom - newHeight
        else
            newTop := MonitorWorkAreaTop    
    }

    WinRestore,A
    WinMove,A,,%newLeft%,%newTop%,%newWidth%,%newHeight%
}

; From http://www.autohotkey.com/board/topic/69464-how-to-determine-a-window-is-in-which-monitor/
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%
}

^#Up::ResizeWin(0)
^#Down::ResizeWin(1)
+^#Up::ResizeWin(0, 1)
+^#Down::ResizeWin(1, 1)

相关内容