Windows 是否有vista的API来检测桌面是否全屏运行?
e、 g,用户是在全屏播放电影,还是在全屏模式下观看powerpointWindows 是否有vista的API来检测桌面是否全屏运行?,windows,winapi,windows-vista,fullscreen,Windows,Winapi,Windows Vista,Fullscreen,e、 g,用户是在全屏播放电影,还是在全屏模式下观看powerpoint 我可以发誓我以前见过IsFullScreenInteractiveAPI,但现在找不到它使用GetForeGroundIndow获取用户正在使用的窗口的句柄。GetClientRect将给出无边框窗口的活动部分的尺寸;使用ClientToScreen将矩形转换为监视器坐标 调用MonitorFromRect或MonitorFromWindow以获取窗口所在的监视器。使用GetMonitorInfo获取监视器的坐标 比较两个
我可以发誓我以前见过IsFullScreenInteractiveAPI,但现在找不到它使用GetForeGroundIndow获取用户正在使用的窗口的句柄。GetClientRect将给出无边框窗口的活动部分的尺寸;使用ClientToScreen将矩形转换为监视器坐标 调用MonitorFromRect或MonitorFromWindow以获取窗口所在的监视器。使用GetMonitorInfo获取监视器的坐标
比较两个矩形-如果窗口矩形完全覆盖监视器矩形,则为全屏窗口。以下是我解决此问题的方法:
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(IsForegroundWwindowFullScreen());
}
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
static extern int GetSystemMetrics(int smIndex);
public const int SM_CXSCREEN = 0;
public const int SM_CYSCREEN = 1;
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, out W32RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct W32RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public static bool IsForegroundWwindowFullScreen()
{
int scrX = GetSystemMetrics(SM_CXSCREEN),
scrY = GetSystemMetrics(SM_CYSCREEN);
IntPtr handle = GetForegroundWindow();
if (handle == IntPtr.Zero) return false;
W32RECT wRect;
if (!GetWindowRect(handle, out wRect)) return false;
return scrX == (wRect.Right - wRect.Left) && scrY == (wRect.Bottom - wRect.Top);
}
}
}
检测窗口状态的首选方法是调用。如果您结合GetForegroundWindow进行此操作,您可以轻松地检查用户是否看到全屏窗口。Vista确实有一个API用于此目的-它被调用。我没有看到任何注释。。。顺便说一句,双重WW让我头疼。。。可能是因为啤酒的缘故,别担心……:)是否有一些事件需要处理以完成相同的事情?当应用程序需要不断地检查某个东西是否进入全屏时,这个解决方案相当笨拙。这太完美了!它甚至比原始问题中列出的原因还要多,原因是为什么您不想显示通知。这很好,但在非主显示器为全屏的情况下不起作用。