안녕하세요! HappyBono 인사드립니다.
대부분의 앱들에서 제공하는 팝업 알림 기능에 단점이 존재한다면, 게임이나 영상물 등의 미디어 컨텐츠를 즐기거나, Microsoft PowerPoint (파워포인트) 앱에서 제공하는 슬라이드 쇼 기능으로 발표 중인 경우, 화면에 팝업 알림이 표시되면서 흐름이 끊기는 경우가 빈번합니다.
특히, 그래픽 카드를 이용한 게임 중에는 팝업 창을 닫거나, 제거하려고 [닫기 (X)] 버튼을 누르면, 창의 포커스가 바탕화면에 위치한 관계로, 즐기던 게임은 최소화되고 바탕 화면으로 전환됩니다. 이로 인하여, 사용자 경험에는 좋지 않은 영향을 끼칠 수 있는데요,
아래와 같이, 다른 프로그램이 전체 화면 [Full-Screen] 으로 실행 중인지 여부를 확인할 수 있는 방법을 구현해보았고, 이를 통해 팝업 창을 표시하기 전, 실행 환경을 감지하여 팝업 창 표시 여부에 대한 조건을 지정해줄 수 있습니다.
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Windows.Forms
Module FullScreenAppsModule
<StructLayout(LayoutKind.Sequential)>
Public Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
<DllImport("user32.dll")>
Private Function GetForegroundWindow() As IntPtr
End Function
<DllImport("user32.dll")>
Private Function GetShellWindow() As IntPtr
End Function
<DllImport("user32.dll")>
Private Function GetWindowRect(ByVal hWnd As IntPtr, ByRef rect As RECT) As Boolean
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)>
Private Function GetClassName(ByVal hWnd As IntPtr,
ByVal lpClassName As StringBuilder,
ByVal nMaxCount As Integer) As Integer
End Function
Public Function IsForegroundFullScreen() As Boolean
Return IsForegroundFullScreen(Nothing)
End Function
Public Function IsForegroundFullScreen(ByVal targetScreen As Screen) As Boolean
Dim hWnd As IntPtr = GetForegroundWindow()
If hWnd = IntPtr.Zero OrElse hWnd = GetShellWindow() Then Return False
' 바탕화면 (Progman / WorkerW) 제외
Dim sb As New StringBuilder(256)
GetClassName(hWnd, sb, sb.Capacity)
Dim cls As String = sb.ToString()
If cls = "Progman" OrElse cls = "WorkerW" Then Return False
Dim rect As RECT
If Not GetWindowRect(hWnd, rect) Then Return False
' 지정한 화면이 없으면 Foreground 창이 있는 모니터 기준
If targetScreen Is Nothing Then
targetScreen = Screen.FromHandle(hWnd)
End If
Dim b = targetScreen.Bounds
' 최대화 창은 보이지 않는 테두리 때문에 화면보다 커서 구분되므로,
' >= 로 완화하지 말고 네 변이 정확히 일치할 때만 전체 화면으로 판단
If rect.left = b.Left AndAlso rect.top = b.Top AndAlso
rect.right = b.Right AndAlso rect.bottom = b.Bottom Then
Debug.WriteLine("Fullscreen apps are running.")
Return True
Else
Debug.WriteLine("Show Popup")
Return False
End If
End Function
End Module
위의 코드를 모듈에 넣고, 아래와 같이 IsForegroundFullScreen() 함수를 호출하셔서 사용하시면 됩니다.
Private Sub ShowNotification()
If IsForegroundFullScreen() Then
' 전체 화면 앱 실행 중인 경우, 팝업 표시를 보류
Return
End If
ShowNotificationForm()
End Sub
도움이 되셨으면 좋겠습니다.
고맙습니다.
