如何强制 Windows 10 在完全相同的位置以完全相同的大小真正打开程序?

KDe*_*ker 7 windows windows-7 windows-10

我最近在家用 PC 上升级到了 Windows 10。在 Windows 7 中,我有一些我经常使用的启动程序,它们设置为在启动时在第二台显示器上打开。这些程序将始终以相同的大小在相同的位置打开。我认为这是 Windows 和/或程序本身的功能。

在 Windows 10 中,我注意到某些程序不显示此行为。它们特别是在同一位置打开,但在水平方向上要短 10-20px。例如,在启动时(甚至在一般使用期间),我将水平最大化 Windows explorer.exe。但是当资源管理器再次打开时,从窗口的左侧和右侧获取 10-20px 的宽度

在此处输入图片说明

在上图中,顶部显示资源管理器已打开并水平最大化。底部显示资源管理器在关闭后再次打开,其默认位置和大小由(我假设)Windows 设置。(浅蓝色是图像背景,黑色是桌面空间中的“无人区”,深灰色是我的桌面背景,红线表示窗口缺失宽度的大致位置)。


如何强制 Windows 10真正并始终在完全相同的位置以完全相同的大小打开程序?

请注意,某些程序没有此问题。特别是 Firefox,它将始终在完全相同的位置以完全相同的大小打开。虽然我完全确定这是 Firefox 的一个功能。鉴于explorer.exe是 Windows,那么我知道这个问题也在 Windows 端。

har*_*ymc 5

存在使用AutoHotkey脚本语言的免费工具 。

名为 gallaxhar 的用户在 自动恢复每个进程的最后一个窗口位置帖子中创建了一个脚本 ,该脚本充当自动窗口管理器,无需用户输入或设置即可保存窗口位置。它通过获取当前活动窗口信息(id 和进程名)来工作。它将最新的窗口大小/位置保存到ini文件中,并在新窗口 ID 变为活动状态时从该文件中读取。它只会在运行后自动调整窗口大小,只会自动调整新 ID 的大小,并且只会为该 ID 执行一次。

安装 AutoHotkey 后,将脚本放入.ahk文件中。通过双击启动进行测试。它的托盘栏中将有一个绿色的“H”图标,您可以右键单击该图标以退出。一旦证明工作正常,您可以将其放入“启动”文件夹中。

我测试了该脚本,它似乎适用于您的场景。

该脚本复制如下:

; Automatically Restore Previous Window Size/Pos

; To make this script run when windows starts, make sure RegistryAdd.ahk is in the same directory as this script, run this script, and it will be added to the registry. Then delete RegistryAdd.ahk
#Include *i RegistryAdd.ahk

; To easily remove the previously added registry entry, make sure RegistryRemove.ahk is in the same directory as this script, run this script, and it will be removed from the registry. Then delete RegistryRemove.ahk
#Include *i RegistryRemove.ahk

#SingleInstance Force
#Persistent
#NoEnv
;#NoTrayIcon
SetWinDelay, 50
Process, Priority, , Normal

MatchList := ""

; Build the MatchList
WinGet, id, list,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    if (MatchList = "")
    MatchList := this_id
    else
    MatchList := MatchList . "," . this_id 
}

; ExclusionList
ExclusionList = ShellExperienceHost.exe,SearchUI.exe

; The main program loop, which manages window positions/sizes and saves their last known configuration to an ini file in the script directory.
Loop,
{
    Sleep, 350
    WinGet, active_id, ID, A
    if active_id not in %MatchList% ; Then this is a new window ID! So, check if it has a configuration saved.
    {
        MatchList := MatchList . "," . active_id ; This window ID is not new anymore!
        WinGet, active_ProcessName, ProcessName, A
        WinGetClass, active_Class, A
        IniRead, savedSizePos, %A_ScriptDir%\WindowSizePosLog.ini, Process Names, %active_ProcessName%
        if (savedSizePos != "ERROR" AND active_Class != "MultitaskingViewFrame" AND active_class != "Shell_TrayWnd") ; Then a saved configuration exists, size/move the window!
        {
            StringSplit OutputArray, savedSizePos,`,
            if (active_ProcessName = "explorer.exe" AND active_Class != "CabinetWClass")
            {

            }
            else
            {
                WinMove, A,, OutputArray1, OutputArray2, OutputArray3, OutputArray4
            }
        }
        else ; No saved configuration exists, save the current window size/pos as a configuration instead!
        {
            WinGetPos X, Y, Width, Height, A
            WinGet, active_ProcessName, ProcessName, A
            WinGetClass, active_Class, A
            If (X != "" AND Y != "" AND Width != "" AND Height != "" AND Width > 0 AND Height > 0 AND active_Class != "MultitaskingViewFrame" AND active_class != "Shell_TrayWnd")
            {
                if (active_ProcessName = "explorer.exe" AND active_Class != "CabinetWClass")
                {

                }
                else if active_ProcessName not in %ExclusionList%
                {
                    IniWrite %X%`,%Y%`,%Width%`,%Height%, %A_ScriptDir%\WindowSizePosLog.ini, Process Names, %active_ProcessName%
                }
            }
        }
    }
    else ; Save/overwrite the active window size and position to a file with a link to the processname, for later use.
    {
        WinGetPos X, Y, Width, Height, A
        WinGet, active_ProcessName, ProcessName, A
        WinGetClass, active_Class, A
        If (X != "" AND Y != "" AND Width != "" AND Height != "" AND Width > 0 AND Height > 0 AND active_Class != "MultitaskingViewFrame" AND active_class != "Shell_TrayWnd")
        {
            if (active_ProcessName = "explorer.exe" AND active_Class != "CabinetWClass")
            {

            }
            else if active_ProcessName not in %ExclusionList%
            {
                IniWrite %X%`,%Y%`,%Width%`,%Height%, %A_ScriptDir%\WindowSizePosLog.ini, Process Names, %active_ProcessName%
            }
        }
    }
}
Return
Run Code Online (Sandbox Code Playgroud)

DeskSoft WindowManager (10 美元,试用版)是一种可以记住并恢复程序和窗口的位置和大小的商业工具 。

该工具将在重新启动后记住位置和大小。