Skip to content

Instantly share code, notes, and snippets.

@CanadianJeff
Created January 20, 2022 16:12
Show Gist options
  • Save CanadianJeff/53ea0c7a94a8595e7be08d6950db06c8 to your computer and use it in GitHub Desktop.
Save CanadianJeff/53ea0c7a94a8595e7be08d6950db06c8 to your computer and use it in GitHub Desktop.
If (!A_IsAdmin){
Run *RunAs "%A_AhkPath%" "%A_ScriptFullPath%"
}
262MACenterLayout()
{
MyCenterWindow(2064, 1288, 2048, 1280) ; Client Size Should Be 2048x1280 8:5 1:1
}
QWXGACenterLayout()
{
MyCenterWindow(2064, 1200, 2048, 1152) ; Client Size Should Be 2048x1152 16:9 1:1
}
WUXGACenterLayout()
{
MyCenterWindow(1936, 1208, 1920, 1200) ; Client Size Should Be 1920x1200 8:5 1:1
}
FHDCenterLayout()
{
MyCenterWindow(1936, 1088, 1920, 1080) ; Client Size Should Be 1920x1080 16:9 1:1
}
WXGAHCenterLayout()
{
MyCenterWindow(1296, 779, 1280, 720) ; Client Size Should Be 1280x720 16:9 1:1
}
;CenterLayout()
;{
; MyCenterWindow()
;}
;CenterLayout()
;{
; MyCenterWindow()
;}
MyActiveWindow(CW, CH)
{
WinGetPos,X,Y,_W_,_H_,A ;ahk is not case sensitive with var names so you need to change W and H
WinGet, HWND, ID, A
WinGetActiveTitle, Title
GetClientSize(HWND, w, h)
MsgBox, %Title% @ (%X%`,%Y%)`nWindow Size (%_W_%x%_H_%)`nClient Size (%w%x%h%)`nExpected Size (%CW%x%CH%)
}
;--------------------------------------------------------------------
MyCenterWindow(W, H, CW, CH)
{
X := A_ScreenWidth/2-W/2
Y := A_ScreenHeight/2-H/2
WinMove, A, , X, Y, W, H
MyActiveWindow(CW, CH)
}
~LButton::
now := A_TickCount
while GetKeyState("LButton", "P")
if (A_TickCount-now > 300)
{
WinGetPos,X,Y,_W_,_H_,A ;ahk is not case sensitive with var names so you need to change W and H
WinGet, HWND, ID, A
GetClientSize(HWND, w, h)
ToolTip,% "WindowSize: " _W_ " x " _H_ "`nClientSize: " w " x " h
Sleep, 1000
}
ToolTip
Return
GetClientSize(HWND, ByRef w, ByRef h)
{
VarSetCapacity(rc, 16)
DllCall("GetClientRect", "uint", HWND, "ptr", &rc)
w := NumGet(rc, 8, "int")
h := NumGet(rc, 12, "int")
}
#Numpad0::MyActiveWindow(0, 0)
#Numpad1::262MACenterLayout()
#Numpad2::QWXGACenterLayout()
#Numpad3::WUXGACenterLayout()
#Numpad4::FHDCenterLayout()
#Numpad5::WXGAHCenterLayout()
#Numpad6::setClientSize(A, 1920, 1080)
; ----------------------------------------------------------------------------------------------------------------------
; GetWindowInfo(HWND)
; Function:
; Retrieves information about the specified window.
; Parameter:
; HWND - A handle to the window whose information is to be retrieved.
; Return value:
; If the function succeeds, the return value is an object containing the information.
; If the function fails, the return value is zero.
; MSDN:
; http://msdn.microsoft.com/en-us/library/ms632610(v=vs.85).aspx
; ----------------------------------------------------------------------------------------------------------------------
GetWindowInfo(HWND) {
Static SizeOfWINDOWINFO := 60
; Struct WINDOWINFO
VarSetCapacity(WINDOWINFO, SizeOfWINDOWINFO, 0)
NumPut(SizeOfWINDOWINFO, WINDOWINFO, "UInt")
If !DllCall("User32.dll\GetWindowInfo", "Ptr", HWND, "Ptr", &WINDOWINFO, "UInt")
Return False
; Object WI
WI := {}
WI.WindowX := NumGet(WINDOWINFO, 4, "Int") ; X coordinate of the window
WI.WindowY := NumGet(WINDOWINFO, 8, "Int") ; Y coordinate of the window
WI.WindowW := NumGet(WINDOWINFO, 12, "Int") - WI.WindowX ; Width of the window
WI.WindowH := NumGet(WINDOWINFO, 16, "Int") - WI.WindowY ; Height of the window
WI.ClientX := NumGet(WINDOWINFO, 20, "Int") ; X coordinate of the client area
WI.ClientY := NumGet(WINDOWINFO, 24, "Int") ; Y coordinate of the client area
WI.ClientW := NumGet(WINDOWINFO, 28, "Int") - WI.ClientX ; Width of the client area
WI.ClientH := NumGet(WINDOWINFO, 32, "Int") - WI.ClientY ; Height of the client area
WI.Style := NumGet(WINDOWINFO, 36, "UInt") ; The window styles.
WI.ExStyle := NumGet(WINDOWINFO, 40, "UInt") ; The extended window styles.
WI.State := NumGet(WINDOWINFO, 44, "UInt") ; The window status (1 = active).
WI.BorderW := NumGet(WINDOWINFO, 48, "UInt") ; The width of the window border, in pixels.
WI.BorderH := NumGet(WINDOWINFO, 52, "UInt") ; The height of the window border, in pixels.
WI.Type := NumGet(WINDOWINFO, 56, "UShort") ; The window class atom.
WI.Version := NumGet(WINDOWINFO, 58, "UShort") ; The Windows version of the application.
Return WI
}
setClientSize(winTitle, width, height) {
WinGet, myHwnd, ID, %winTitle%
WinGetPos, myX, myY, myW, myH, %winTitle%
my := GetWindowInfo(myHwnd)
newW := width + (my.WindowW - my.ClientW)
newH := height + (my.WindowH - my.ClientH)
WinMove, %winTitle%, , myX, myY, newW, newH
}
traySetSize(width, height) {
SendInput, !{Esc}
Sleep, 10
setClientSize("A", width, height)
}
trayExit() {
ExitApp
}
;Menu, Tray, Icon, icons\r.ico
Menu, Tray, NoStandard
Menu, Tray, Add, 1280 x 720, % setRes_1280_720
Menu, Tray, Add, 1920 x 1080, % setRes_1920_1080
Menu, Tray, Add
Menu, Tray, Add, Exit, trayExit
return
;^#s::Menu, Tray, Show
; Unused Junk Below This Line
#left::MoveLayoutLeft()
#right::MoveLayoutRight()
#+left::ShrinkWidthLayout()
#+right::EnlargWidthLayout()
#+up::HeightLayout()
MyCenterLeftLayout()
{
WinGetPos,,, W, H, A
WinMove, A,, (A_ScreenWidth/2)-(W/2), (A_ScreenHeight/2)-(H/2)
}
MoveLayoutRight()
{
WinGetPos, X, , Width, , A
Delta := A_ScreenWidth / 8
NewX := X + Delta
if (NewX > (A_ScreenWidth - Width)) {
NewX := A_ScreenWidth - Width
}
WinMove, A, , %NewX%, , ,
}
MoveLayoutLeft()
{
WinGetPos, X, , Width, , A
Delta := A_ScreenWidth / 8
NewX := X - Delta
if (NewX < 0) {
NewX := 0
}
WinMove, A, , %NewX%, , ,
}
ShrinkWidthLayout()
{
WinGetPos, , , Width, , A
Delta := A_ScreenWidth / 8
NewWidth := Width - Delta
if (NewWidth < Delta) {
NewWidth := Delta
}
WinMove, A, , , , %NewWidth%,
}
EnlargWidthLayout()
{
WinGetPos, X, , Width, , A
Delta := A_ScreenWidth / 8
NewWidth := Width + Delta
if ((X + NewWidth) > A_ScreenWidth) {
NewWidth := A_ScreenWidth - X
}
WinMove, A, , , , %NewWidth%,
}
TwoThirdsLayoutRight()
{
; WinGetPos, X, Y, Width, Height, A
; WinMove, A, , X + (Width / 2) -10, , Width / 2 +10,
ActWin := WinActive("A")
WinMove, A, , A_ScreenWidth / 3, , A_ScreenWidth - (A_ScreenWidth / 3),
; Send, {Alt Down}{Tab}{Alt Up}
Send, !{Esc}
Sleep, 150
WinMove, A, , 0, , A_ScreenWidth / 3,
; from: https://jacks-autohotkey-blog.com/2020/04/20/autohotkey-tricks-for-tracking-activating-target-process-windows/#more-41349
WinActivate, ahk_id %ActWin%
}
HeightLayout()
{
WinMove, A, , , 50, , A_ScreenHeight-100
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment