-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathIsFullScreen.ahk
81 lines (70 loc) · 3.73 KB
/
IsFullScreen.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
; https://autohotkey.com/board/topic/50876-isfullscreen-checks-if-a-window-is-in-fullscreen-mode/
/*! TheGood
Checks if a window is in fullscreen mode.
______________________________________________________________________________________________________________
sWinTitle - WinTitle of the window to check. Same syntax as the WinTitle parameter of, e.g., WinExist().
bRefreshRes - Forces a refresh of monitor data (necessary if resolution has changed)
Return value o If window is fullscreen, returns the index of the monitor on which the window is fullscreen.
o If window is not fullscreen, returns False.
ErrorLevel - Sets ErrorLevel to True if no window could match sWinTitle
Based on the information found at http://support.microsoft.com/kb/179363/ which discusses under what
circumstances does a program cover the taskbar. Even if the window passed to IsFullscreen is not the
foreground application, IsFullscreen will check if, were it the foreground, it would cover the taskbar.
*/
IsFullscreen(sWinTitle = "A", bRefreshRes = False) {
Static
Local iWinX, iWinY, iWinW, iWinH, iCltX, iCltY, iCltW, iCltH, iMidX, iMidY, iMonitor, c, D, iBestD
ErrorLevel := False
If bRefreshRes Or Not Mon0 {
SysGet, Mon0, MonitorCount
SysGet, iPrimaryMon, MonitorPrimary
Loop %Mon0% { ;Loop through each monitor
SysGet, Mon%A_Index%, Monitor, %A_Index%
Mon%A_Index%MidX := Mon%A_Index%Left + Ceil((Mon%A_Index%Right - Mon%A_Index%Left) / 2)
Mon%A_Index%MidY := Mon%A_Index%Top + Ceil((Mon%A_Index%Top - Mon%A_Index%Bottom) / 2)
}
}
;Get the active window's dimension
hWin := WinExist(sWinTitle)
If Not hWin {
ErrorLevel := True
Return False
}
;Make sure it's not desktop
WinGetClass, c, ahk_id %hWin%
If (hWin = DllCall("GetDesktopWindow") Or (c = "Progman") Or (c = "WorkerW"))
Return False
;Get the window and client area, and style
VarSetCapacity(iWinRect, 16), VarSetCapacity(iCltRect, 16)
DllCall("GetWindowRect", UInt, hWin, UInt, &iWinRect)
DllCall("GetClientRect", UInt, hWin, UInt, &iCltRect)
WinGet, iStyle, Style, ahk_id %hWin%
;Extract coords and sizes
iWinX := NumGet(iWinRect, 0), iWinY := NumGet(iWinRect, 4)
iWinW := NumGet(iWinRect, 8) - NumGet(iWinRect, 0) ;Bottom-right coordinates are exclusive
iWinH := NumGet(iWinRect, 12) - NumGet(iWinRect, 4) ;Bottom-right coordinates are exclusive
iCltX := 0, iCltY := 0 ;Client upper-left always (0,0)
iCltW := NumGet(iCltRect, 8), iCltH := NumGet(iCltRect, 12)
;Check in which monitor it lies
iMidX := iWinX + Ceil(iWinW / 2)
iMidY := iWinY + Ceil(iWinH / 2)
;Loop through every monitor and calculate the distance to each monitor
iBestD := 0xFFFFFFFF
Loop % Mon0 {
D := Sqrt((iMidX - Mon%A_Index%MidX)**2 + (iMidY - Mon%A_Index%MidY)**2)
If (D < iBestD) {
iBestD := D
iMonitor := A_Index
}
}
;Check if the client area covers the whole screen
bCovers := (iCltX <= Mon%iMonitor%Left) And (iCltY <= Mon%iMonitor%Top) And (iCltW >= Mon%iMonitor%Right - Mon%iMonitor%Left) And (iCltH >= Mon%iMonitor%Bottom - Mon%iMonitor%Top)
If bCovers
Return True
;Check if the window area covers the whole screen and styles
bCovers := (iWinX <= Mon%iMonitor%Left) And (iWinY <= Mon%iMonitor%Top) And (iWinW >= Mon%iMonitor%Right - Mon%iMonitor%Left) And (iWinH >= Mon%iMonitor%Bottom - Mon%iMonitor%Top)
If bCovers { ;WS_THICKFRAME or WS_CAPTION
bCovers := bCovers And (Not (iStyle & 0x00040000) Or Not (iStyle & 0x00C00000))
Return bCovers ? iMonitor : False
} Else Return False
}