Некоторое время назад я создал скрипт, который «нормализует» окна, т. е. изменяет размер, перемещает и выполняет другие действия, чтобы окно соответствовало моим личным предпочтениям.
Всякий раз, когда окно отображается в первый раз, оно нормализуется. Если его закрыть и снова открыть, он снова нормализуется.
Ниже приведена работающая версия скрипта, которая должна удовлетворять требованиям исходного вопроса.
Версия, которую я использую, намного сложнее, потому что в ней гораздо больше функций, например. он поддерживает несколько мониторов и изменяет размеры окон с учетом высоты панели задач Windows. Я использую скрипт, чтобы увеличить диалоги открытия/сохранения (по умолчанию они слишком маленькие). Я также использую его для автоматического входа на некоторые веб-сайты и приложения.
; This script "normalizes" windows, i.e. resizes, moves, and performs other
; actions to make a window confirm to my personal preference.
SetTitleMatchMode, 2
; Go into an infinite loop
loop
{
; Pause so other apps can execute. 250 milliseconds seems to work well.
Sleep, 250
; If hotkeys are suspended for this script, then suspend all functionality
if A_IsSuspended
continue
; We will build a unique window name using the window title and window handle.
; Store each unique name in an array.
WinGet, HWND, ID, A
WinGetTitle, WindowTitle, A
WinGetClass, WindowClass, A
; Remember the previous window we processed
WindowTitleCleanPrevious := WindowTitleClean
; Only normalize windows that we haven't seen before.
; If we haven't already normalized the window, we do
; the normalize, then set a flag so we don't normalize the same window again.
; Strip out all chars that may be invalid in an AHK variable name.
WindowTitleCleanTemp := StringRemoveAllNonAlphaNum(WindowTitle)
; Variable names can be at most 254 chars, so truncate to less than that.
StringLeft, WindowTitleClean, WindowTitleCleanTemp, 230
; Process the window if:
; (1) It wasn't previously processed (i.e. not in our window-name list named WinList)
; (2) And we aren't sitting on the same window during each loop.
if (WinList%HWND%%WindowTitleClean% != 1 and WindowTitleClean != WindowTitleCleanPrevious)
{
; Get the window's position and size
WinGetPos, WinX, WinY, WinWidth, WinHeight, A
; Is this an MS Word window?
if (WindowClass == "OpusApp")
{
; Center the window and resize so it is 80% of the monitor width and 90% of height.
WinMove, A, , (A_ScreenWidth/2)-(WinWidth/2), (A_ScreenHeight/2)-(WinHeight/2), A_ScreenWidth * .8, A_ScreenHeight * .9
}
; Is this the Calculator window?
else if (WindowClass == "SciCalc")
{
; Center the window
WinMove, A, , (A_ScreenWidth/2)-(WinWidth/2), (A_ScreenHeight/2)-(WinHeight/2)
}
; Set a flag indicating this window has been processed so it is
; not processed again.
WinList%HWND%%WindowTitleClean% = 1
}
}
; --- Win+F5 will Reload this script ---
~#F5::Reload
; --- Win+Escape will Pause this script ---
~#Escape::Suspend, Toggle
; --- Win+Alt+Escape will Exit this script ---
; Close this script
~#!Escape::ExitApp
; ===========================================================================
; Removes all non-alphabetic and non-numeric characters from the given
; string. The resulting string is returned.
; ===========================================================================
StringRemoveAllNonAlphaNum(SourceString)
{
StringSplit, SplitSourceString, SourceString
OutputString =
Loop, %SplitSourceString0%
{
Char := SplitSourceString%A_Index%
if (Char >= "a") and (Char <= "z")
OutputString := OutputString Char
else if (Char >= "0") and (Char <= "9")
OutputString := OutputString Char
}
return OutputString
}
person
Dean Hill
schedule
22.11.2010