Set of window functions
Win | Set of window functions |
Animate | Enables you to produce special effects when showing or hiding windows. |
Get | Get window information |
GetRect | Get window rectangle. |
Is | Checks handle against specified criterium. |
Move | Change the size and position of a child, pop-up, or top-level window. |
MoveDelta | Move the window by specified amount. |
Recall | Store & recall window position, size and/or state. |
Redraw | Redraws the window. |
SetCaption | Set visibility of the window caption. |
SetMenu | Set the window menu. |
SetIcon | Set the titlebar icon for the window. |
SetParent | Changes the parent window of the specified window. |
SetOwner | Changes the owner window of the specified window. |
Show | Show / Hide window. |
ShowSysMenu | Show system menu for a window (ALT + SPACE menu). |
Subclass | Subclass child window (control) |
About |
Win_Animate( Hwnd, Type = "", Time = 100 )
Enables you to produce special effects when showing or hiding windows.
Type | White space separated list of animation flags. By default, these flags take effect when showing a window. |
Time | Specifies how long it takes to play the animation, in millisecond . |
activate | Activates the window. Do not use this value with HIDE flag. |
blend | Uses a fade effect. This flag can be used only if hwnd is a top-level window. |
center | Makes the window appear to collapse inward if HIDE is used or expand outward if the HIDE is not used. The various direction flags have no effect. |
hide | Hides the window. By default, the window is shown. |
slide | Uses slide animation. Ignored when used with CENTER. |
hneg | Animates the window from right to left. This flag can be used with roll or slide animation. It is ignored when used with CENTER or BLEND. |
hpos | Animates the window from left to right. This flag can be used with roll or slide animation. It is ignored when used with CENTER or BLEND. |
vneg | Animates the window from top to bottom. This flag can be used with roll or slide animation. It is ignored when used with CENTER or BLEND. |
vpos | Animates the window from bottom to top. This flag can be used with roll or slide animation. It is ignored when used with CENTER or BLEND. |
When using slide or roll animation, you must specify the direction. You can combine HPOS or HNEG with VPOS or VNEG to animate a window diagonally. If a child window is displayed partially clipped, when it is animated it will have holes where it is clipped. Avoid animating a window that has a drop shadow because it produces visually distracting, jerky animations.
If the function succeeds, the return value is nonzero.
Win_Animate(hWnd, "hide blend", 500)
Win_Get( Hwnd, pQ = "", ByRef o1 = "", ByRef o2 = "", ByRef o3 = "", ByRef o4 = "", ByRef o5 = "", ByRef o6 = "", ByRef o7 = "", ByRef o8 = "", ByRef o9 = "" )
Get window information
pQ | List of query parameters. |
o1 .. o9 | Reference to output variables. R,L,B & N query parameters can return multiple outputs. |
C,I | Class, pId. |
R,L,B,N | One of the window rectangles: R (window Rectangle), L (cLient rectangle screen coordinates), B (ver/hor Border), N (captioN rect). N gives size of the caption regardless of the window style. These coordinates include all title-bar elements except the window menu. The function returns x, y, w & h separated by space. For all 4 query parameters you can additionaly specify x,y,w,h arguments in any order (except Border which can have only x(hor) and y(ver) arguments) to extract desired number into ouput variable. |
S,E | Style, Extended style |
P,A,O | Parents handle, Ancestors handle, Owners handle |
M | Module full path (owner exe), unlike WinGet,,ProcessName which returns only name without path. |
T | Title for top level windows or Text for child windows |
o1
Win_Get(hwnd, "CIT", class, pid, text) ;get class, pid and text Win_Get(hwnd, "RxwTC", x, w, t, c) ;get x & width attributes of window rect, title and class Win_Get(hwnd, "RxywhCLxyTBy",wx,wy,ww,wh,c,lx,ly,t,b) ;get all 4 attributes of window rect, class, x & y of client rect, text and horizontal border height right := Win_Get(hwnd, "Rx") + Win_Get(hwnd, "Rw") ;first output is returned as function result so u can use function in expressions. Win_Get(hwnd, "Rxw", x, w), right := x+w ;the same as above but faster right := Win_Get(hwnd, "Rxw", x, w ) + w ;not recommended
Win_GetRect( hwnd, pQ = "", ByRef o1 = "", ByRef o2 = "", ByRef o3 = "", ByRef o4 = "" )
Get window rectangle.
hwnd | Window handle |
pQ | Query parameter: ordered list of x, y, w and h characters. If you specify * as first char rectangle will be raltive to the client area of window’s parent. Leave pQ empty or “*” to return all attributes separated by space. |
o1 .. o4 | Reference to output variables. |
o1
This function is faster alternative to Get with R parameter. However, if you query additional window info using Get, it may be faster and definitely more convenient then obtaining the info using alternatives. Besides that, you can’t use Get to obtain relative coordinates of child windows.
Win_GetRect(hwnd, "xw", x, w) ;get x & width Win_GetRect(hwnd, "yhx", y, h, x) ;get y, height, and x p := Win_GetRect(hwnd, "x") + 5 ;for single query parameter you don't need output variable as function returns o1 all := Win_GetRect(hwnd) ;return all Win_Get(hwnd, "*hx", h, x) ;return relative h and x all_rel := WiN_Get(hwnd, "*") ;return all relative coorinates
Win_Is( Hwnd, pQ = "win" )
Checks handle against specified criterium.
pQ | Query parameter. |
win | True if handle is window. |
child | True if handle is child window. |
enabled | True if window is enabled. |
visible | True if window is visible. |
max | True if window is maximized. |
hung | True if window is hung and doesn’t respond to messages. |
TRUE or FALSE
Win_Move( Hwnd, X = "", Y = "", W = "", H = "", Flags = "" )
Change the size and position of a child, pop-up, or top-level window.
X..H | Size / position. You can omit any parameter to keep its current value. |
Flags | Can be R or A. |
R | Does not redraw changes. If this flag is set, no repainting of any kind occurs. |
A | Asynchronous mode - if the calling thread and the thread that owns the window are attached to different input queues, the system posts the request to the thread that owns the window. This prevents the calling thread from blocking its execution while other threads process the request. |
True if successful, False otherwise.
Does not produce the same effect as ControlMove on child windows. Mentioned AHK function puts child window relative to the ancestor window rectangle while Win_Move puts it relative to the parent’s client rectangle which is usually the wanted behavior. WinMove produces the same effect as Win_Move on child controls, except its X and Y parameters are not optional which makes lot of addtional code for frequent operation: moving the control by some offset of its current position. In order to do that you must get the current position of the control. That can be done with ControlGetPos which works in pair with ControlMove hence it is not relative to the client rect or WinGetPos which returns screen coordinates of child control so those can not be imediatelly used in WinMove as it positions child window relative to the parents client rect. This scenario can be additionaly complicated by the fact that each window may have its own theme which influences the size of its borders, non client area, etc...
Win_MoveDelta( Hwnd, Xd = "", Yd = "", Wd = "", Hd = "", Flags = "" )
Move the window by specified amount.
Xd .. Hd | Delta to add to each window rect property. Skipped properties will not be changed. |
Flags | The same as in Move. |
True if successful, False otherwise.
Win_Recall( Options, Hwnd = "", IniFileName = "" )
Store & recall window position, size and/or state.
Options | White space separated list of options. See bellow. |
Hwnd | Hwnd of the window for which to store data or Gui number if AHK window. If omitted, function will use Hwnd of the default AHK Gui. You can also use Gui, N:Default prior to calling the function. For 3td party windows, this parameter is mandatory. Set 0 as hwnd to return position string without applying it to any window. This can be used for AHK Guis to calculate size of controls based on window size and position, when needed. |
IniFileName | Ini file to use as storage. Function will save the data under the [Recall] section. If omited, Windows Registry key HKEY_CURRENT_USER\AutoHotKey\Win is used. Each script is uniquely determined by its full path so same scripts with different name will not share the storage. |
”>”, “<”, “-”, “--” | Operation, mandatory option. Use “>” to store or “<” to recall window position. It can be optionally followed by the string representing the name of the storage location for that window. You need to use name if your script stores more then one window, otherwise it will be saved under unnamed location. “>” and “<” are special names that can be used to store or recall all AHK Guis. “-” operation is used alone as an argument to delete Registry or Ini sections belonging to the script. “--” operation is used alone as an argument to delete all Registry entries for all scripts. |
-Min | Don’t save minimize state. |
-Max | Don’t save maximized state. |
Position string, space separated list of syntax “left top right bottom state cw ch” of the window. Empty if no recall data is stored for the window. State can be 1 (normal) 2 (minimized) or 3 (maximized). cw & ch numbers are present only for AHK Guis and represent client width & height which can be used without modifications in Gui, Show command.
Single Gui Example:
Gui, +Resize +LastFound WinSetTitle, MyGui if !Win_Recall("<") ;Recall gui if its position is already saved Gui, Show, h300 w300, MyGui ; otherwise use these defaults. return GuiClose: Win_Recall(">") ;Store the Gui. ExitApp return
Win_Recall(">MyGui") ;Save position for default Gui under name MyGui. Win_Recall("<MyGui") ;Recall position for MyGui for default Gui Win_Recall(">MyGui2", Hwnd) ;Save window position under MyGui2 name, given the window handle or Gui number. Win_Recall(">>") ;Save all Guis. The names will be given by their number. Win_Recall("<<") ;Recall all Guis. Win_Recall("-") ;Delete all Registry enteries for the script. Win_Recall("--") ;Delete all Registry enteries for all scripts. pos := Win_Recall("<MyWin", 0) ;Return position string only for window saved under the "MyWin" name.
Win_SetIcon( Hwnd, Icon = "", Flag = 1 )
Set the titlebar icon for the window.
Icon | Path to the icon. If omited, icon is removed. If integer, handle to the already loaded icon. |
Flag | 1 sets the large icon for the window, 0 sets the small icon for the window. |
The return value is a handle to the previous large or small icon, depending on the Flag value.
Win_SetParent( Hwnd, hParent = )
Changes the parent window of the specified window.
hParent | Handle to the parent window. If this parameter is 0, the desktop window becomes the new parent window. |
If the function succeeds, the return value is a handle to the previous parent window.
Changes the owner window of the specified window.
hOwner | Handle to the owner window. |
Handle of the previous owner.
An owned window is always above its owner in the z-order. The system automatically destroys an owned window when its owner is destroyed. An owned window is hidden when its owner is minimized. Only an overlapped or pop-up window can be an owner window; a child window cannot be an owner window.
Win_Subclass( hCtrl, Fun, Opt = "", ByRef $WndProc = "" )
Subclass child window (control)
hCtrl | Handle to the child window to be subclassed |
Fun | New window procedure. You can also pass function address here in order to subclass child window with previously created window procedure. |
Opt | Optional callback options for Fun, by default “” |
$WndProc | Optional reference to the ouptut variable that will receive address of the new window procedure. |
The addresss of to the previous window procedure or 0 on error
Works only for controls created in the autohotkey process.
if !Win_SubClass(hwndList, "MyWindowProc") MsgBox, Subclassing failed. ... MyWindowProc(hwnd, uMsg, wParam, lParam){ if (uMsg = .....) ; my message handling here return DllCall("CallWindowProcA", "UInt", A_EventInfo, "UInt", hwnd, "UInt", uMsg, "UInt", wParam, "UInt", lParam) }
Enables you to produce special effects when showing or hiding windows.
Win_Animate( Hwnd, Type = "", Time = 100 )
Get window information
Win_Get( Hwnd, pQ = "", ByRef o1 = "", ByRef o2 = "", ByRef o3 = "", ByRef o4 = "", ByRef o5 = "", ByRef o6 = "", ByRef o7 = "", ByRef o8 = "", ByRef o9 = "" )
Get window rectangle.
Win_GetRect( hwnd, pQ = "", ByRef o1 = "", ByRef o2 = "", ByRef o3 = "", ByRef o4 = "" )
Checks handle against specified criterium.
Win_Is( Hwnd, pQ = "win" )
Change the size and position of a child, pop-up, or top-level window.
Win_Move( Hwnd, X = "", Y = "", W = "", H = "", Flags = "" )
Move the window by specified amount.
Win_MoveDelta( Hwnd, Xd = "", Yd = "", Wd = "", Hd = "", Flags = "" )
Store & recall window position, size and/or state.
Win_Recall( Options, Hwnd = "", IniFileName = "" )
Redraws the window.
Win_Redraw( Hwnd = )
Set visibility of the window caption.
Win_SetCaption( Hwnd, Flag = "^" )
Set the window menu.
Win_SetMenu( Hwnd, hMenu = )
Set the titlebar icon for the window.
Win_SetIcon( Hwnd, Icon = "", Flag = 1 )
Changes the parent window of the specified window.
Win_SetParent( Hwnd, hParent = )
Show / Hide window.
Win_Show( Hwnd, bShow = true )
Show system menu for a window (ALT + SPACE menu).
Win_ShowSysMenu( Hwnd, X = "mouse", Y = "" )
Subclass child window (control)
Win_Subclass( hCtrl, Fun, Opt = "", ByRef $WndProc = "" )