Code:
#NoEnv
#SingleInstance force
f1::
drawFrameAroundWin(WinExist("a"), "Red", 4, 1, true)
return
; mode=1: Draw frame around whole window
; mode=2: Draw frame around client area
; if inside is true, the frame will be drawn towards
; the "inside" of the table instead of around it, i.e. it
; will overlap with the table
drawFrameAroundWin(win, color, thickness, mode=1, inside=false, gui=0) {
t:=thickness
ifEqual, mode, 1, {
WinGetPos, x, y, w, h, ahk_id%win%
if inside
x+=thickness, y+=thickness, w-=thickness*2, h-=thickness*2
return drawFrame(x, y, w, h, color, thickness, gui)
} else ifEqual, mode, 2, {
getClientRect(x, y, w, h, win)
if inside
x+=thickness, y+=thickness, w-=thickness*2, h-=thickness*2
return drawFrame(x, y, w, h, color, thickness, gui)
} else {
msgbox No such mode!
}
}
drawFrame(x, y, w, h, color, thickness, gui=0) {
t:=thickness
x1:=0, y1:=0
x2:=w+t*2, y2:=y1
x3:=x2, y3:=h+t*2
x4:=x1, y4:=y3
x5:=x1, y5:=y1
x6:=t, y6:=t
x7:=x2-t, y7:=y6
x8:=x7, y8:=y3-t
x9:=x6, y9:=y8
x10:=x6, y10:=y6
Loop 10
region.=x%a_index% "-" y%a_index% " "
gui:=gui ? gui : freeGui()
Gui, %gui%:default
Gui, +lastfound +alwaysOnTop +toolwindow -caption
Gui, Color, % color
x:=x-t, y:=y-t, w:=w+t*2, h:=h+t*2
Gui, Show, x%x% y%y% w%w% h%h% hide, Frame (Gui #: %gui%)
WinSet, Region, % region
Gui, Show, noActivate
return gui
}
; finds the next free gui
freeGui(startIdx=0) {
Loop % (99-startIdx) {
startIdx++
Gui, %startIdx%: +lastfoundExist
If ! WinExist()
return startIdx
}
}
/**
* Finds the "client rectangle" of a window, i.e. the area of
* the window not including borders, titlebar, menus, etc.
*
* @param x <int> Receives the x-coordinate of the window.
* @param y <int> Receives the y-coordinate of the window.
* @param w <int> Receives the width of the window.
* @param h <int> Receives the height of the window.
* @param hwnd <hwnd> Window handle. If blank, the Last Found Window will be used.
* @author Adapted from code by Sean. Modified and updated to use
* NumGet()/NumPut() by Roland.
* @see http://msdn.microsoft.com/en-us/library/ms633503(VS.85).aspx
* @see http://msdn.microsoft.com/en-us/library/aa931003.aspx
*/
getClientRect(byRef x="", byRef y="", byRef w="", byRef h="", hwnd=0) {
hwnd:=hwnd ? hwnd : WinExist() ; use LFW if no hwnd given
VarSetCapacity(rt, 16) ; alloc. mem. for RECT struc.
VarSetCapacity(pt, 8, 0) ; alloc. mem. for POINT struc.
DllCall("GetClientRect" , "uint", hwnd, "uint", &rt)
DllCall("ClientToScreen", "uint", hwnd, "uint", &pt)
x:=NumGet(pt, 0, "int"), y:=NumGet(pt, 4, "int")
w:=NumGet(rt, 8, "int"), h:=NumGet(rt, 12, "int")
}