2008-10-14 12 views

답변

2

사용 GetForegroundWindow를 찾을 수 없습니다. GetClientRect는 윈도우의 활성 부분의 크기를 보냅니다. ClientToScreen을 사용하여 직사각형을 모니터 좌표로 변환하십시오.

MonitorFromRect 또는 MonitorFromWindow를 호출하여 윈도우가있는 모니터를 가져옵니다. GetMonitorInfo를 사용하여 모니터 좌표를 가져옵니다.

두 직사각형 비교 - 창이 직사각형이 모니터 사각형을 완전히 덮는 경우 전체 화면 창입니다. 여기

4

내가이 문제를 해결 한 방법은 다음과 같습니다

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); 
     } 
    } 
} 
+0

나는 아무런 코멘트도 보지 못했다 ... BTW, 두 배의 WW는 두통을 줬다. 맥주 때문일 수도 있고, 걱정하지 마라. :) – hannson

+0

처리 할 이벤트가 있는가? 같은 것? 이 솔루션은 응용 프로그램이 무언가가 전체 화면에 입력되었는지 여부를 지속적으로 확인해야 할 때 상당히 까다 롭습니다. –

0

윈도우의 상태를 감지 선호되는 방법은 GetWindowPlacement를 호출하는 것입니다. GetForegroundWindow와 함께 사용하면 사용자가 전체 화면 창을 볼 수 있는지 여부를 쉽게 확인할 수 있습니다.

3

Vista는 실제로이 목적을 위해 정확하게 정확히 API를 가지고 있습니다. 이것은 SHQueryUserNotificationState입니다.

+1

이것은 완벽합니다! 원래의 질문에 열거 된 것보다 더 많은 이유들로, 왜 당신이 통보를 보여주고 싶지 않은지에 대한 이유가 있습니다. – Thiru

+0

이것은 좋지만, 비 기본 모니터가 전체 화면 인 상황에서는 작동하지 않습니다. – HaveSpacesuit