Skip to content

Commit 291c33b

Browse files
committed
correct namespace
correct namespace to make it easier, and increment version
1 parent 172ff89 commit 291c33b

File tree

3 files changed

+130
-126
lines changed

3 files changed

+130
-126
lines changed

FullScreenDetection/FullScreenDetection.vbproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
77
<ProjectGuid>{41B380B5-DEF2-4B4A-BF99-4275617CD86A}</ProjectGuid>
88
<OutputType>Library</OutputType>
9-
<RootNamespace>FullScreenDetection</RootNamespace>
9+
<RootNamespace>Narod</RootNamespace>
1010
<AssemblyName>FullScreenDetection</AssemblyName>
1111
<FileAlignment>512</FileAlignment>
1212
<MyType>Windows</MyType>
@@ -18,7 +18,7 @@
1818
<PropertyGroup>
1919
<PackageId>Narod.FullscreenDetector</PackageId>
2020
<Title>Narod's Fullscreen Detector</Title>
21-
<Version>1.2.0</Version>
21+
<Version>2.0.0</Version>
2222
<Authors>NarodGaming</Authors>
2323
<Owner>NarodGaming</Owner>
2424
<PackageDescription>A library containing fullscreen application detection functions.</PackageDescription>

FullScreenDetection/FullscreenDetector.vb

Lines changed: 124 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -6,125 +6,129 @@ Imports System.Drawing
66
Imports System.Runtime.InteropServices
77
Imports System.Windows.Forms
88

9-
Public Structure RECT
10-
Public Left As Integer
11-
Public Top As Integer
12-
Public Right As Integer
13-
Public Bottom As Integer
14-
End Structure
15-
16-
Public Class FullscreenDetector
17-
Private HasDetected As Boolean = Nothing
18-
Private ProgramDetected As String = Nothing
19-
Private ProcessIDDetected As UInteger = Nothing
20-
21-
''' <summary>
22-
''' Returns if a fullscreen application has been detected from the last detection run.
23-
''' </summary>
24-
''' <returns>
25-
''' 0 = no fullscreen application detected. 1 = fullscreen application detected.
26-
''' </returns>
27-
Public Function GetHasDetected() As Boolean
28-
If HasDetected = Nothing Then ' if hasdetected is still nothing which would be set from init
29-
Throw New NullReferenceException("Attempted to check if fullscreen application was detected before the detection method was run.") ' throw exception with verbose message to hopefully help user
30-
Return False ' in case of a try/catch to ignore above error, return false instead
31-
End If
32-
Return HasDetected ' return
33-
End Function
34-
35-
''' <summary>
36-
''' Returns the program name that has been detected from the last detection run.
37-
''' </summary>
38-
''' <returns>
39-
''' The window title of the program that has been detected. Throws NullReferenceException if no fullscreen application detected.
40-
''' </returns>
41-
Public Function GetProgramDetected() As String
42-
If ProgramDetected = Nothing Then ' if programdetected is still nothing which would be set from init
43-
Throw New NullReferenceException("Attempted to check name of fullscreen application before the detection method was run, or when no fullscreen application was detected.") ' throw exception with verbose message to hopefully help user
44-
Return "" ' in case of a try/catch to ignore above error, return blank string instead
45-
End If
46-
Return ProgramDetected ' return
47-
End Function
48-
49-
''' <summary>
50-
''' Returns the process ID that has been detected from the last detection run.
51-
''' </summary>
52-
''' <returns>
53-
''' The process ID of the program that has been detected. Throws NullReferenceException if no fullscreen application detected.
54-
''' </returns>
55-
Public Function GetProcessIDDetected() As UInteger
56-
If ProcessIDDetected = Nothing Then ' if processiddetected is still nothing which would be set from init
57-
Throw New NullReferenceException("Attempted to check process ID of fullscreen application before the detection method was run, or when no fullscreen application was detected.") ' throw exception with verbose message to hopefully help user
58-
Return 0 ' in case of a try/catch to ignore above error, return 0 integer instead
59-
End If
60-
Return ProcessIDDetected
61-
End Function
62-
63-
<DllImport("user32.dll")>
64-
Private Shared Function GetForegroundWindow() As IntPtr
65-
66-
End Function
67-
<DllImport("user32.dll")>
68-
Private Shared Function GetDesktopWindow() As IntPtr
69-
70-
End Function
71-
<DllImport("user32.dll")>
72-
Private Shared Function GetShellWindow() As IntPtr
73-
74-
End Function
75-
<DllImport("user32.dll")>
76-
Private Shared Function GetWindowRect(ByVal hwnd As IntPtr, <Out> ByRef rc As RECT) As Integer
77-
78-
End Function
79-
<DllImport("user32.dll")>
80-
Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As Integer) As Integer
81-
82-
End Function
83-
<DllImport("user32.dll")>
84-
Private Shared Function GetWindowThreadProcessId(ByVal hWnd As IntPtr, <Out> ByRef processId As UInteger) As UInteger
85-
86-
End Function
87-
88-
Private runningFullScreen As Boolean = False
89-
Private windowText As New System.Text.StringBuilder(256)
90-
Private appBounds As New RECT
91-
Private screenBounds As New Rectangle
92-
Private hWnd As New IntPtr
93-
94-
Private desktopHandle As New IntPtr
95-
Private shellHandle As New IntPtr
96-
97-
''' <summary>
98-
''' Checks for any fullscreen application in-use, and stores it in the object.
99-
'''
100-
''' Take a look at the 'Get' functions provided by the object for output.
101-
''' </summary>
102-
Public Sub DetectFullscreenApplication() ' this is a base function which can be used to pull ANY fullscreen window, including web browsers.
103-
hWnd = GetForegroundWindow() ' assumed to be the fullscreen program, is actually just the current window in focus
104-
desktopHandle = GetDesktopWindow() ' gets the desktop window, as to check that it isn't the desktop which is in focus
105-
shellHandle = GetShellWindow() ' gets the shell window, as to check that it isn't the shell (usually explorer.exe) which is in focus
106-
107-
If Not hWnd = Nothing And Not hWnd.Equals(IntPtr.Zero) Then ' checks to make sure there actually is a currently focussed window, and that the focussed window is valid (not hidden, etc)
108-
If Not (hWnd.Equals(desktopHandle) Or hWnd.Equals(shellHandle)) Then ' checks to see if the application doesn't match the desktop window (would likely happen if no window focussed), and that it doesn't match the shell application (usually explorer.exe)
109-
GetWindowRect(hWnd, appBounds) ' gets the window size of the application it is going to check
110-
screenBounds = Screen.FromHandle(hWnd).Bounds ' gets the current monitor size (resolution)
111-
If ((appBounds.Bottom - appBounds.Top) = screenBounds.Height And (appBounds.Right - appBounds.Left) = screenBounds.Width) Then ' aka if window is fullscreen
112-
runningFullScreen = True ' set boolean to True
113-
GetWindowText(GetForegroundWindow, windowText, windowText.Capacity) ' get window text of application
9+
Namespace FullscreenDetection
10+
11+
Public Structure RECT
12+
Public Left As Integer
13+
Public Top As Integer
14+
Public Right As Integer
15+
Public Bottom As Integer
16+
End Structure
17+
18+
Public Class FullscreenDetector
19+
Private HasDetected As Boolean = Nothing
20+
Private ProgramDetected As String = Nothing
21+
Private ProcessIDDetected As UInteger = Nothing
22+
23+
''' <summary>
24+
''' Returns if a fullscreen application has been detected from the last detection run.
25+
''' </summary>
26+
''' <returns>
27+
''' 0 = no fullscreen application detected. 1 = fullscreen application detected.
28+
''' </returns>
29+
Public Function GetHasDetected() As Boolean
30+
If HasDetected = Nothing Then ' if hasdetected is still nothing which would be set from init
31+
Throw New NullReferenceException("Attempted to check if fullscreen application was detected before the detection method was run.") ' throw exception with verbose message to hopefully help user
32+
Return False ' in case of a try/catch to ignore above error, return false instead
33+
End If
34+
Return HasDetected ' return
35+
End Function
36+
37+
''' <summary>
38+
''' Returns the program name that has been detected from the last detection run.
39+
''' </summary>
40+
''' <returns>
41+
''' The window title of the program that has been detected. Throws NullReferenceException if no fullscreen application detected.
42+
''' </returns>
43+
Public Function GetProgramDetected() As String
44+
If ProgramDetected = Nothing Then ' if programdetected is still nothing which would be set from init
45+
Throw New NullReferenceException("Attempted to check name of fullscreen application before the detection method was run, or when no fullscreen application was detected.") ' throw exception with verbose message to hopefully help user
46+
Return "" ' in case of a try/catch to ignore above error, return blank string instead
47+
End If
48+
Return ProgramDetected ' return
49+
End Function
50+
51+
''' <summary>
52+
''' Returns the process ID that has been detected from the last detection run.
53+
''' </summary>
54+
''' <returns>
55+
''' The process ID of the program that has been detected. Throws NullReferenceException if no fullscreen application detected.
56+
''' </returns>
57+
Public Function GetProcessIDDetected() As UInteger
58+
If ProcessIDDetected = Nothing Then ' if processiddetected is still nothing which would be set from init
59+
Throw New NullReferenceException("Attempted to check process ID of fullscreen application before the detection method was run, or when no fullscreen application was detected.") ' throw exception with verbose message to hopefully help user
60+
Return 0 ' in case of a try/catch to ignore above error, return 0 integer instead
61+
End If
62+
Return ProcessIDDetected
63+
End Function
64+
65+
<DllImport("user32.dll")>
66+
Private Shared Function GetForegroundWindow() As IntPtr
67+
68+
End Function
69+
<DllImport("user32.dll")>
70+
Private Shared Function GetDesktopWindow() As IntPtr
71+
72+
End Function
73+
<DllImport("user32.dll")>
74+
Private Shared Function GetShellWindow() As IntPtr
75+
76+
End Function
77+
<DllImport("user32.dll")>
78+
Private Shared Function GetWindowRect(ByVal hwnd As IntPtr, <Out> ByRef rc As RECT) As Integer
79+
80+
End Function
81+
<DllImport("user32.dll")>
82+
Private Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As Integer) As Integer
83+
84+
End Function
85+
<DllImport("user32.dll")>
86+
Private Shared Function GetWindowThreadProcessId(ByVal hWnd As IntPtr, <Out> ByRef processId As UInteger) As UInteger
87+
88+
End Function
89+
90+
Private runningFullScreen As Boolean = False
91+
Private windowText As New System.Text.StringBuilder(256)
92+
Private appBounds As New RECT
93+
Private screenBounds As New Rectangle
94+
Private hWnd As New IntPtr
95+
96+
Private desktopHandle As New IntPtr
97+
Private shellHandle As New IntPtr
98+
99+
''' <summary>
100+
''' Checks for any fullscreen application in-use, and stores it in the object.
101+
'''
102+
''' Take a look at the 'Get' functions provided by the object for output.
103+
''' </summary>
104+
Public Sub DetectFullscreenApplication() ' this is a base function which can be used to pull ANY fullscreen window, including web browsers.
105+
hWnd = GetForegroundWindow() ' assumed to be the fullscreen program, is actually just the current window in focus
106+
desktopHandle = GetDesktopWindow() ' gets the desktop window, as to check that it isn't the desktop which is in focus
107+
shellHandle = GetShellWindow() ' gets the shell window, as to check that it isn't the shell (usually explorer.exe) which is in focus
108+
109+
If Not hWnd = Nothing And Not hWnd.Equals(IntPtr.Zero) Then ' checks to make sure there actually is a currently focussed window, and that the focussed window is valid (not hidden, etc)
110+
If Not (hWnd.Equals(desktopHandle) Or hWnd.Equals(shellHandle)) Then ' checks to see if the application doesn't match the desktop window (would likely happen if no window focussed), and that it doesn't match the shell application (usually explorer.exe)
111+
GetWindowRect(hWnd, appBounds) ' gets the window size of the application it is going to check
112+
screenBounds = Screen.FromHandle(hWnd).Bounds ' gets the current monitor size (resolution)
113+
If ((appBounds.Bottom - appBounds.Top) = screenBounds.Height And (appBounds.Right - appBounds.Left) = screenBounds.Width) Then ' aka if window is fullscreen
114+
runningFullScreen = True ' set boolean to True
115+
GetWindowText(GetForegroundWindow, windowText, windowText.Capacity) ' get window text of application
116+
End If
114117
End If
115118
End If
116-
End If
117-
HasDetected = runningFullScreen
118-
If runningFullScreen = True Then ' only run if fullscreen application was detected
119-
ProgramDetected = windowText.ToString
120-
Dim processId As UInteger ' create variable to store process ID of application in
121-
GetWindowThreadProcessId(hWnd, processId) ' get process ID of that specific application/window
122-
ProcessIDDetected = processId
123-
Else
124-
ProgramDetected = Nothing
125-
ProcessIDDetected = Nothing
126-
End If
127-
runningFullScreen = False ' prevents requirement for reinit
128-
End Sub
129-
130-
End Class
119+
HasDetected = runningFullScreen
120+
If runningFullScreen = True Then ' only run if fullscreen application was detected
121+
ProgramDetected = windowText.ToString
122+
Dim processId As UInteger ' create variable to store process ID of application in
123+
GetWindowThreadProcessId(hWnd, processId) ' get process ID of that specific application/window
124+
ProcessIDDetected = processId
125+
Else
126+
ProgramDetected = Nothing
127+
ProcessIDDetected = Nothing
128+
End If
129+
runningFullScreen = False ' prevents requirement for reinit
130+
End Sub
131+
132+
End Class
133+
134+
End Namespace

FullScreenDetection/My Project/Settings.Designer.vb

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)