Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !Enter::FullScreen("A") ; press alt enter to fullscreen current window
- ; toggle fullscreen
- ; parameters are same as WinExist
- Fullscreen(winTitle*) {
- static prevX := "AHK:Fullscreen.prevX"
- static prevY := "AHK:Fullscreen.prevY"
- static prevW := "AHK:Fullscreen.prevW"
- static prevH := "AHK:Fullscreen.prevH"
- static prevStyle := "AHK:Fullscreen.prevStyle"
- static IsFullscreen := "AHK:Fullscreen.IsFullscreen"
- static IsSwitching := "AHK:Fullscreen.SwitchingMonitor"
- static SPI_GETWORKAREA := 0x30
- static SPI_SETWORKAREA := 0x2F
- static WS_EX_TRANSPARENT := 0x00000020
- static WS_EX_LAYERED := 0x00080000
- static WS_EX_COMPOSITED := 0x02000000
- static WS_SIZEBOX := 0x00040000
- static WS_SYSMENU := 0x00080000
- static WS_CAPTION := 0x00C00000
- static WS_MAXIMIZE := 0x01000000
- static g := (
- g := Gui("+AlwaysOnTop -Caption +ToolWindow -DPIScale +Border +E" WS_EX_TRANSPARENT|WS_EX_COMPOSITED|WS_EX_LAYERED),
- g.MarginX := 5,
- g.BackColor := 0x1A1A1A,
- g.SetFont("s18 cWhite", "Segoe UI SemiBold"),
- g.Add("Text", "vText w230 h35 Center"),
- g
- )
- if !hwnd := WinExist(winTitle*)
- return
- if WinExist("ahk_id " hwnd " ahk_exe ApplicationFrameHost.exe")
- {
- WinActivate hwnd
- Send "#+{Enter}"
- return
- }
- ; static _ := CreateF11Group()
- ; CreateF11Group() {
- ; GroupAdd "FullscreenF11", "ahk_class ahk_class Chrome_WidgetWin_1"
- ; GroupAdd "FullscreenF11", "ahk_class ahk_class MozillaWindowClass"
- ; return
- ; }
- ; if WinExist("ahk_id " hwnd " ahk_group FullscreenF11")
- ; {
- ; WinActivate(hwnd)
- ; Send "{F11}"
- ; return
- ; }
- ; create hotkey to move fullscreen window to next monitor
- HotIfWinActive "ahk_id " hwnd
- Hotkey "$#+Left", MoveWindowToNextMonitor, "On"
- Hotkey "$#+Right", MoveWindowToNextMonitor, "On"
- ; create a hotkey to keep the window on top of tray if LWin is pressed
- HotIf MouseIsOverFullScreenWindow
- Hotkey "~LWin", KeepWindowOnTopOfTray, "On"
- mon := GetNearestMonitor(hwnd)
- monSwitch := WinGetProp(hwnd, IsSwitching)
- SetWinDelay -1
- if !WinGetProp(hwnd, IsFullscreen) {
- if mon.Primary {
- NumPut("int", A_ScreenWidth, "int", A_ScreenHeight, rc := Buffer(16, 0), 8)
- DllCall("SystemParametersInfo", "uint", SPI_SETWORKAREA, "UInt", 0, "Ptr", rc, "UInt", 0)
- MoveTrayBehindWindow(hwnd)
- } else {
- RestoreWorkingArea()
- }
- wp := GetWindowPlacement(hwnd)
- if !monSwitch {
- WinGetPos(, &winY,,, hwnd)
- WinGetClientPos(, &clientY,,, hwnd)
- WinSetProp(hwnd, prevStyle, WinGetStyle(hwnd))
- WinSetStyle "-" ((clientY-winY>8) ? WS_CAPTION|WS_SIZEBOX : WS_SYSMENU), hwnd ; remove title bar
- }
- WinMove(mon.Left, mon.Top, mon.Width, mon.Height, hwnd)
- WinSetStyle("+" WS_MAXIMIZE, hwnd)
- SetWindowPlacement(hwnd, wp.X, wp.Y, wp.W, wp.H)
- WinSetProp(hwnd, IsFullscreen, 1, prevX, wp.X, prevY, wp.Y, prevW, wp.W, prevH, wp.H)
- g["Text"].Text := "FullScreen Enabled"
- } else {
- ; turn off hotkeys
- HotIfWinActive "ahk_id " hwnd
- Hotkey "$#+Left", "Off"
- Hotkey "$#+Right", "Off"
- HotIf MouseIsOverFullScreenWindow
- Hotkey "~LWin", "Off"
- RestoreWorkingArea()
- X := WinGetProp(hwnd, prevX), Y := WinGetProp(hwnd, prevY), W := WinGetProp(hwnd, prevW), H := WinGetProp(hwnd, prevH)
- style := WinGetProp(hwnd, prevStyle)
- WinSetStyle(style, hwnd)
- if !WinGetMinMax(hwnd) = 1
- WinMove(X, Y, W, H, hwnd)
- else if mon.Primary {
- WinGetPos ,,,&H, GetTray()
- WinMove(,,,mon.Height - H,hwnd)
- }
- ; Put tray on top
- DllCall("SetWindowPos", "ptr", GetTray(), "int", -1, "int", 0, "int", 0, "int", 0, "int", 0, "uint", 0x4000|0x0010|0x0002|0x0001) ; SWP_ASYNCWINDOWPOS|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE
- WinSetProp hwnd, IsFullscreen, 0
- g["Text"].Text := "FullScreen Disabled"
- }
- if !monSwitch {
- g.Show("NA x" Mon.Left + Mon.Width//2 - 210/2 " y" Mon.Top + 30)
- SetTimer () => g.Hide(), -1000
- }
- static RestoreWorkingArea() {
- DllCall("SystemParametersInfo", "uint", SPI_GETWORKAREA, "uint", 0, "ptr", rc := Buffer(16), "uint", 0)
- if NumGet(rc, 12, "int") = A_ScreenHeight { ; if working area height is same as A_ScreenHeight
- WinGetPos(,,, &H, GetTray())
- NumPut("int", A_ScreenHeight - H, rc, 12)
- DllCall("SystemParametersInfo", "uint", SPI_SETWORKAREA, "uint", 0, "ptr", rc, "uint", 0)
- }
- }
- static KeepWindowOnTopOfTray(*) {
- hwnd := WinExist() ; Get last found window from HotIf
- KeyWait "LWin"
- sleep 250
- tray := GetTray()
- for win in WinGetList() {
- if win = hwnd
- break
- if win = tray {
- MoveTrayBehindWindow(hwnd)
- break
- }
- }
- }
- ; get hwnd of taskbar
- static GetTray() => DllCall("FindWindow", "str", "Shell_TrayWnd", "str", "")
- ; keep window above taskbar when fullscreen
- static MoveTrayBehindWindow(hwnd) {
- DllCall("SetWindowPos",
- "ptr", GetTray(),
- "ptr", hwnd,
- "int", 0, "int", 0, "int", 0, "int", 0,
- "uint", 0x4000|0x0010|0x0002|0x0001) ; SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE
- }
- static MouseIsOverFullScreenWindow(*) {
- MouseGetPos ,,&hwnd
- if WinGetProp(hwnd, IsFullscreen)
- return WinExist(hwnd)
- }
- static MoveWindowToNextMonitor(ThisHotkey) {
- hwnd := WinExist()
- Send "{Blind}#+" (InStr(ThisHotkey, "Left") ? "{Left}" : "{Right}")
- Sleep 250
- WinSetProp hwnd, IsFullscreen, 0, IsSwitching, 1
- FullScreen hwnd
- WinSetProp hwnd, IsSwitching, 0
- }
- ; save properties on a window
- static WinSetProp(hwnd, propValue*) {
- if propValue.Length & 1
- throw Error("Invalid number of parameters.", -1)
- loop propValue.Length // 2 {
- prop := propValue[A_Index*2 - 1], value := propValue[A_Index*2]
- if value > 0xFFFFFFFF
- throw Error("value is too big", -1, value)
- DllCall("SetProp", "ptr", hwnd, "str", prop, "int", value)
- }
- }
- static WinGetProp(hwnd, name) {
- return DllCall("GetProp", "ptr", hwnd, "str", name) & 0xFFFFFFFF
- }
- static GetNearestMonitor(hwnd) {
- static MONITOR_DEFAULTTONEAREST := 0x00000002
- NumPut("uint", 40, monInfo := Buffer(40))
- DllCall("GetMonitorInfo", "ptr", DllCall("MonitorFromWindow", "ptr", hwnd, "uint", MONITOR_DEFAULTTONEAREST), "ptr", monInfo)
- return {
- Left : L := NumGet(monInfo, 4, "int"),
- Top : T := NumGet(monInfo, 8, "int"),
- Width : NumGet(monInfo, 12, "Int") - L,
- Height : NumGet(monInfo, 16, "int") - T,
- Primary : NumGet(monInfo, 36, "uint")
- }
- }
- static GetWindowPlacement(hwnd) {
- NumPut("uint", 44, WP := Buffer(44, 0))
- DllCall("GetWindowPlacement", "ptr", hwnd, "ptr", WP)
- return {
- SW : NumGet(WP, 8, "uint"), ; showCmds - current show state of the window
- X : X := NumGet(WP, 28, "Int"),
- Y : Y := NumGet(WP, 32, "Int"),
- W : NumGet(WP, 36, "Int") - X,
- H : NumGet(WP, 40, "Int") - Y,
- }
- }
- static SetWindowPlacement(hwnd, X, Y, W, H) {
- NumPut("uint", 44, WP := Buffer(44, 0))
- DllCall("GetWindowPlacement", "Ptr", hwnd, "Ptr", WP)
- , NumPut("int", X, WP, 28)
- , NumPut("int", Y, WP, 32)
- , NumPut("int", W + X, WP, 36)
- , NumPut("int", H + Y, WP, 40)
- DllCall("SetWindowPlacement", "ptr", hwnd, "ptr", WP)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement