Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Standard Headers
- #NoEnv
- #Warn
- SendMode Input
- SetWorkingDir %A_ScriptDir%
- ; The Hotkey
- #f::
- ; Get the active window and its style.
- WinGet, WindowID, ID, A
- WinGet, Style, Style, ahk_id %WindowID%
- ; If true, blow up the window, otherwise restore it.
- If (Style & 0xC40000)
- {
- ; Get the window geometry and save it with the window ID for later.
- WinGetPos, PosX_%WindowID%, PosY_%WindowID%, W_%WindowID%, H_%WindowID%, ahk_id %WindowID%
- ; Figure out the center.
- xc := PosX_%WindowID% + W_%WindowID%/2
- yc := PosY_%WindowID% + H_%WindowID%/2
- ; Now get the monitor the window center is on.
- MID := FindMonitor(xc, yc)
- SysGet, mn, Monitor, %MID%
- ; Calculate monitor size.
- mnWidth := mnRight - mnLeft
- mnHeight := mnBottom - mnTop
- ; Now, remove the window caption and border, and move the window to fill
- ; the whole monitor.
- WinSet, Style, -0xC40000, ahk_id %WindowID%
- WinMove, ahk_id %WindowID%, , %mnLeft%, %mnTop%, %mnWidth%, %mnHeight%
- }
- Else
- {
- ; First, get back the caption and border.
- WinSet, Style, +0xC40000, ahk_id %WindowID%
- ; Now, if we have variables for the window, restore its position, otherwise
- ; fall back to moving it to a visible spot. This should never happen though.
- If (H_%WindowID% <> 0)
- {
- WinMove, ahk_id %WindowID%, , PosX_%WindowID%, PosY_%WindowID%, W_%WindowID%, H_%WindowID%
- }
- Else
- {
- WinMove, ahk_id %WindowID%, , 50, 50, 500, 500
- }
- }
- return
- ; Helper Functions
- FindMonitor(xc, yc)
- {
- SysGet, mc, MonitorCount
- Loop, %mc%
- {
- SysGet, moni, Monitor, %A_Index%
- if (xc >= moniLeft and xc <= moniRight and yc >= moniTop and yc <= moniBottom)
- {
- return %A_Index%
- }
- }
- return 0
- }
Advertisement
Add Comment
Please, Sign In to add comment