Yet Another Borderless Window Toggle

Post gaming related scripts
Hastarin
Posts: 2
Joined: 04 Dec 2014, 21:15

Yet Another Borderless Window Toggle

04 Dec 2014, 21:26

Hi folks,

I came across a script on the old forum to toggle a window fullscreen borderless.

Unfortunately it didn't quite work as I wanted with Steam In-Home Streaming as it still left the re-size border (~5 pixels) around the window.

I managed to update it to work as intended on Windows 8.1 so thought I'd share it with the wider community.

Code: Select all

/*  YABT - Yet Another Borderless-Window Toggle
 *  by Barrow (March 30, 2012)
 *  rewritten by kon (May 16, 2014)
 *  http://www.autohotkey.com/board/topic/78903-yabt-yet-another-borderless-window-toggle/page-2#entry650488
 *  updated by Hastarin (Dec 5, 2014)
 *  tested with AutoHotkey v1.1.16.05
 */
#w::Toggle_Window(WinExist("A"))    ; Win+W to maximize the active window
!^w::Toggle_Window()                ; Ctrl+Alt+W to maximize the window under the mouse

Toggle_Window(Window:="") {
    static A := Init()
    if (!Window)
        MouseGetPos,,, Window
    WinGet, S, Style, % (i := "_" Window) ? "ahk_id " Window :  ; Get window style
    if (S & +0xC00000) {                                        ; If not borderless
        WinGet, IsMaxed, MinMax,  % "ahk_id " Window
        if (A[i, "Maxed"] := IsMaxed = 1 ? true : false)
            WinRestore, % "ahk_id " Window
        WinGetPos, X, Y, W, H, % "ahk_id " Window               ; Store window size/location
        for k, v in ["X", "Y", "W", "H"]
            A[i, v] := %v%
        Loop, % A.MCount {                                      ; Determine which monitor to use
            if (X >= A.Monitor[A_Index].Left
            &&  X <  A.Monitor[A_Index].Right
            &&  Y >= A.Monitor[A_Index].Top
            &&  Y <  A.Monitor[A_Index].Bottom) {
                WinSet, Style, -0xC00000, % "ahk_id " Window    ; Remove borders
		WinSet, Style, -0x40000, % "ahk_id " Window    ; Including the resize border
                ; The following lines are the x,y,w,h of the maximized window
                ; ie. to offset the window 10 pixels up: A.Monitor[A_Index].Top - 10
                WinMove, % "ahk_id " Window,
                , A.Monitor[A_Index].Left                               ; X position
                , A.Monitor[A_Index].Top                                ; Y position
                , A.Monitor[A_Index].Right - A.Monitor[A_Index].Left    ; Width
                , A.Monitor[A_Index].Bottom - A.Monitor[A_Index].Top    ; Height
                break
            }
        }
    }
    else if (S & -0xC00000) {                                           ; If borderless
	WinSet, Style, +0x40000, % "ahk_id " Window    		; Reapply borders
        WinSet, Style, +0xC00000, % "ahk_id " Window
        WinMove, % "ahk_id " Window,, A[i].X, A[i].Y, A[i].W, A[i].H    ; Return to original position
        if (A[i].Maxed)
            WinMaximize, % "ahk_id " Window
        A.Remove(i)
    }
}

Init() {
    A := {}
    SysGet, n, MonitorCount
    Loop, % A.MCount := n {
        SysGet, Mon, Monitor, % i := A_Index
        for k, v in ["Left", "Right", "Top", "Bottom"]
            A["Monitor", i, v] := Mon%v%
    }
    return A
}
EpicnessCoding
Posts: 31
Joined: 19 Jan 2015, 01:23

Re: Yet Another Borderless Window Toggle

21 Jan 2015, 21:35

Nice! How do you toggle the window's border on/off? What key do you press?
Hastarin
Posts: 2
Joined: 04 Dec 2014, 21:15

Re: Yet Another Borderless Window Toggle

21 Jan 2015, 21:43

EpicnessCoding wrote:Nice! How do you toggle the window's border on/off? What key do you press?
It's right there in the script. ;)

Code: Select all

#w::Toggle_Window(WinExist("A"))    ; Win+W to maximize the active window
!^w::Toggle_Window()                ; Ctrl+Alt+W to maximize the window under the mouse
I've only used/tested the Windows+W combination myself though.
User avatar
WAZAAAAA
Posts: 88
Joined: 13 Jan 2015, 19:48

Re: Yet Another Borderless Window Toggle

26 Sep 2016, 19:51

The script on the first post doesn't hide WS_EX_CLIENTEDGE, which some windows have. This is my slightly modified version which hides it:

Code: Select all

/*  YABT+ - Yet Another Borderless-Window Toggle
 *  by Barrow (March 30, 2012)
 *  rewritten by kon (May 16, 2014)
 *  http://www.autohotkey.com/board/topic/78903-yabt-yet-another-borderless-window-toggle/page-2#entry650488
 *  updated by Hastarin (Dec 5, 2014)
 *  updated by WAZAAAAA (Sep 27, 2016)
 *  tested with AutoHotkey v1.1.24.01
 */
#w::Toggle_Window(WinExist("A"))    ; Win+W to maximize the active window
!^w::Toggle_Window()                ; Ctrl+Alt+W to maximize the window under the mouse

Toggle_Window(Window:="") {
	static A := Init()
	if (!Window)
		MouseGetPos,,, Window
	WinGet, S, Style, % (i := "_" Window) ? "ahk_id " Window :  ; Get window style
	if (S & +0xC00000) {                                        ; If not borderless
		WinGet, IsMaxed, MinMax,  % "ahk_id " Window
	if (A[i, "Maxed"] := IsMaxed = 1 ? true : false)
		WinRestore, % "ahk_id " Window
	WinGetPos, X, Y, W, H, % "ahk_id " Window               ; Store window size/location
	for k, v in ["X", "Y", "W", "H"]
		A[i, v] := %v%
	Loop, % A.MCount {                                      ; Determine which monitor to use
		if (X >= A.Monitor[A_Index].Left
			&&  X <  A.Monitor[A_Index].Right
	&&  Y >= A.Monitor[A_Index].Top
	&&  Y <  A.Monitor[A_Index].Bottom) {
		WinSet, Style, -0xC00000, % "ahk_id " Window    ; Remove borders
		WinSet, Style, -0x40000, % "ahk_id " Window    ; Including the resize border
		WinSet, ExStyle, -0x00000200, % "ahk_id " Window ;Also WS_EX_CLIENTEDGE
		; The following lines are the x,y,w,h of the maximized window
		; ie. to offset the window 10 pixels up: A.Monitor[A_Index].Top - 10
		WinMove, % "ahk_id " Window,
		, A.Monitor[A_Index].Left                               ; X position
		, A.Monitor[A_Index].Top                                ; Y position
		, A.Monitor[A_Index].Right - A.Monitor[A_Index].Left    ; Width
		, A.Monitor[A_Index].Bottom - A.Monitor[A_Index].Top    ; Height
		break
	}
}
}
else if (S & -0xC00000) {                                           ; If borderless
	WinSet, Style, +0x40000, % "ahk_id " Window    		; Reapply borders
WinSet, Style, +0xC00000, % "ahk_id " Window
WinSet, ExStyle, +0x00000200, % "ahk_id " Window ;Also WS_EX_CLIENTEDGE
WinMove, % "ahk_id " Window,, A[i].X, A[i].Y, A[i].W, A[i].H    ; Return to original position
if (A[i].Maxed)
	WinMaximize, % "ahk_id " Window
A.Remove(i)
}
}

Init() {
	A := {}
	SysGet, n, MonitorCount
	Loop, % A.MCount := n {
		SysGet, Mon, Monitor, % i := A_Index
		for k, v in ["Left", "Right", "Top", "Bottom"]
			A["Monitor", i, v] := Mon%v%
	}
	return A
}
YOU'RE NOT ALEXANDER
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Yet Another Borderless Window Toggle

28 Dec 2016, 14:02

Example Hotkeys (same as above):

Code: Select all

#w::FWT(WinExist("A"))    ; Win+W to fullscreen the active window
!^w::FWT()                ; Ctrl+Alt+W to fullscreen the window under the mouse
Function:

Code: Select all

; FWT - Fullscreen window toggle
; https://autohotkey.com/boards/viewtopic.php?p=123166#p123166
FWT(hwnd:="") {
    static MONITOR_DEFAULTTONEAREST := 0x00000002
    static WS_CAPTION               := 0x00C00000
    static WS_SIZEBOX               := 0x00040000
    static WindowStyle              := WS_CAPTION|WS_SIZEBOX
    static A                        := []
    if (!hwnd)                    ; If no window handle is supplied, use the window under the mouse
        MouseGetPos,,, hwnd
    Win := "ahk_id " hwnd                                                          ; Store WinTitle
    WinGet, S, Style, % Win                                                      ; Get window style
    if (S & WindowStyle) {                                                      ; If not borderless
        A[Win, "Style"] := S & WindowStyle                                   ; Store existing style
        WinGet, IsMaxed, MinMax, % Win                  ; Get/store whether the window is maximized
        if (A[Win, "Maxed"] := IsMaxed = 1 ? true : false)
            WinRestore, % Win
        WinGetPos, X, Y, W, H, % Win                                   ; Store window size/location
        A[Win, "X"] := X, A[Win, "Y"] := Y, A[Win, "W"] := W, A[Win, "H"] := H
        WinSet, Style, % -WindowStyle, % Win                                       ; Remove borders
        hMon := DllCall("User32\MonitorFromWindow", "Ptr", hwnd, "UInt", MONITOR_DEFAULTTONEAREST)
        VarSetCapacity(monInfo, 40), NumPut(40, monInfo, 0, "UInt")
        DllCall("User32\GetMonitorInfo", "Ptr", hMon, "Ptr", &monInfo)
        WinMove, % Win,,  monLeft   := NumGet(monInfo,  4, "Int")          ; Move and resize window
                       ,  monTop    := NumGet(monInfo,  8, "Int")
                       , (monRight  := NumGet(monInfo, 12, "Int")) - monLeft
                       , (monBottom := NumGet(monInfo, 16, "Int")) - monTop
    }
    else if A[Win] {                                                                ; If borderless
        WinSet, Style, % "+" A[Win].Style, % Win                                  ; Reapply borders
        WinMove, % Win,, A[Win].X, A[Win].Y, A[Win].W, A[Win].H       ; Return to original position
        if (A[Win].Maxed)                                                    ; Maximize if required
            WinMaximize, % Win
        A.Delete(Win)
    }
}
werwedsawer
Posts: 5
Joined: 15 Dec 2016, 08:14

Re: Yet Another Borderless Window Toggle

28 Dec 2016, 16:52

Lol, try ctrl+alt+w on your desktop, you can see borders of your desktop :D

Return to “Gaming Scripts (v1)”

Who is online

Users browsing this forum: No registered users and 39 guests