我的英语不太好,但我试着制作一个逻辑故事。
我喜欢家庭domotica,所以我在visual basic(视觉工作室)制作了一个控制房间闪电的程序(使用Arduino)。当我以全屏运行应用程序(用于电影,游戏)时,程序的功能是打开/关闭灯。我使用了一个代码来检测来自互联网的全屏,但是用于比较forgroundscreen和桌面的部分是不行的,我得到一个错误的全屏。 :
Private Function detectfullscreen()
'Detect if the current app is running in full screen
Dim runningFullScreen As Boolean = False
Dim appBounds As RECT
Dim screenBounds As Rectangle
Dim hWnd As IntPtr
'get the dimensions of the active window
hWnd = GetForegroundWindow()
If hWnd <> Nothing AndAlso Not hWnd.Equals(IntPtr.Zero) Then
'Check we haven't picked up the desktop or the shell
If Not (hWnd.Equals(desktopHandle) OrElse hWnd.Equals(shellHandle)) Then
'If hWnd <> GetDesktopWindow() Then
GetWindowRect(hWnd, appBounds)
'determine if window is fullscreen
screenBounds = Screen.FromHandle(hWnd).Bounds
If (appBounds.Bottom - appBounds.Top) = screenBounds.Height AndAlso (appBounds.Right - appBounds.Left) = screenBounds.Width Then
runningFullScreen = True
End If
End If
End If
Return runningFullScreen
End Function
de代码的其余部分(对于寄存器)是:
<StructLayout(LayoutKind.Sequential)> Public Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
Private desktopHandle As IntPtr = GetDesktopWindow()
Private shellHandle As IntPtr = GetShellWindow()
<DllImport("user32.dll")> Private Shared Function GetForegroundWindow() As IntPtr
End Function
<DllImport("user32.dll")> Private Shared Function GetDesktopWindow() As IntPtr
End Function
代码工作正常,我使用计时器来运行这个子程序,但如果我去桌面,该程序还认为我使用的是全屏应用程序。
我的操作系统是Windows 10,我是否可能需要另一种方法来检测当前的forgroundscreen是否为桌面?我尝试使用桌面的de ID,但是当我重新启动计算机时,此ID将会更改。
我很清楚我的故事。感谢您阅读本文!