Code: Select all
; EXTENDED_FRAME_BOUNDS width is 0 with +Resize
Gui New, +Hwndhwnd ; +Resize
Gui Show, w300 h300
MsgBox
Win10Move("ahk_id " . hwnd, 0, 0)
return
GuiEscape:
GuiClose:
ExitApp
Win10Move(wintitle, x:="", y:="", w:="", h:="")
{
; should probably check for OS version, a bit lazy right now
WinGet hwnd, ID, %wintitle% ; WinExist() sets the last found window
static init := false
static offset_x, offset_y, offset_w, offset_h
if (!init) {
; you can probably retrieve just one of the coordinates for each RECT structure
; since the extended frame width is the all the same but for the purpose of
; understanding the function, let's choose verbosity.
VarSetCapacity(RECT, 16, 0)
DllCall("GetWindowRect", "Ptr", hwnd, "Ptr", &RECT)
left := NumGet(RECT, 0, "Int")
top := NumGet(RECT, 4, "Int")
right := NumGet(RECT, 8, "Int")
bottom := NumGet(RECT, 12, "Int")
VarSetCapacity(EXTENDED_FRAME_BOUNDS, 16, 0)
DllCall("dwmapi\DwmGetWindowAttribute", "Ptr", hwnd, "UInt", 9, "Ptr", &EXTENDED_FRAME_BOUNDS, "UInt", 16)
ex_left := NumGet(EXTENDED_FRAME_BOUNDS, 0, "Int")
ex_top := NumGet(EXTENDED_FRAME_BOUNDS, 4, "Int")
ex_right := NumGet(EXTENDED_FRAME_BOUNDS, 8, "Int")
ex_bottom := NumGet(EXTENDED_FRAME_BOUNDS, 12, "Int")
offset_x := left-ex_left
offset_y := top-ex_top
offset_w := (ex_right-ex_left) - (right-left)
offset_h := (ex_bottom-ex_top) - (bottom-top)
init := true
}
if (x != "")
x -= offset_x
if (y != "")
y -= offset_y
if (w != "")
w += offset_w
if (h != "")
h += offset_h
WinMove ahk_id %hwnd%,, %x%, %y%, %w%, %h%
}