是否有用于Vista的API来检测桌面是否正在全屏运行? [英] Is there an API for vista to detect if the desktop is running full screen?
本文介绍了是否有用于Vista的API来检测桌面是否正在全屏运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,用户是在全屏播放电影还是在全屏模式下查看Powerpoint?
e.g, Is the user playing a movie full screen, or looking at powerpoint in full screen mode?
我可能发誓我以前见过IsFullScreenInteractive API,但现在找不到它
I could have sworn I saw a IsFullScreenInteractive API before, but can't find it now
推荐答案
这是我解决此问题的方法:
Here's how I've solved this problem:
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);
}
}
}
这篇关于是否有用于Vista的API来检测桌面是否正在全屏运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文