2010-01-09 2 views
10

Windows 작업 표시 줄이 숨겨져 있는지 여부를 알아야합니다. 나는 이것을 수행 할 .NET 메소드가 없다고 생각하며, 또한 "작업 표시 줄을 숨기고 표시하는 방법"을 많이 보았지만 찾고있는 것을 기반으로하는 것을 본 적이 없다. Windows API에 익숙하지 않아 전통적인 Windows 코드를 이해하기 어렵습니다. 누군가 나에게 기사 나 타입 코드를 알려주면 작업 표시 줄의 현재 상태가 감추어 져 있는지 여부를 알 수 있습니까? 나는 C#으로 코딩하고있다.Windows 작업 표시 줄이 숨겨져 있는지 여부를 프로그래밍 방식으로 결정하는 방법은 무엇입니까?

감사합니다.

답변

10

winSharp93은 작동하는 것처럼 보이는 도우미 클래스 ("Find out Size (and position) of the taskbar")를 제공합니다. Win32의 SHAppBarMessage function을 사용합니다.

여기에 자신의 블로그에서 (작은 추가로) 코드입니다 :

using System; 
using System.Drawing; 
using System.Runtime.InteropServices; 

namespace TaskbarTest 
{ 
    public enum TaskbarPosition 
    { 
     Unknown = -1, 
     Left, 
     Top, 
     Right, 
     Bottom, 
    } 

    public sealed class Taskbar 
    { 
     private const string ClassName = "Shell_TrayWnd"; 

     public Rectangle Bounds { 
      get; 
      private set; 
     } 
     public TaskbarPosition Position { 
      get; 
      private set; 
     } 
     public Point Location { 
      get { 
       return this.Bounds.Location; 
      } 
     } 
     public Size Size { 
      get { 
       return this.Bounds.Size; 
      } 
     } 
     //Always returns false under Windows 7 
     public bool AlwaysOnTop { 
      get; 
      private set; 
     } 
     public bool AutoHide { 
      get; 
      private set; 
     } 

     public Taskbar() { 
      IntPtr taskbarHandle = User32.FindWindow(Taskbar.ClassName, null); 

      APPBARDATA data = new APPBARDATA(); 
      data.cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA)); 
      data.hWnd = taskbarHandle; 
      IntPtr result = Shell32.SHAppBarMessage(ABM.GetTaskbarPos, ref data); 
      if (result == IntPtr.Zero) 
       throw new InvalidOperationException(); 

      this.Position = (TaskbarPosition)data.uEdge; 
      this.Bounds = Rectangle.FromLTRB(data.rc.left, data.rc.top, data.rc.right, data.rc.bottom); 

      data.cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA)); 
      result = Shell32.SHAppBarMessage(ABM.GetState, ref data); 
      int state = result.ToInt32(); 
      this.AlwaysOnTop = (state & ABS.AlwaysOnTop) == ABS.AlwaysOnTop; 
      this.AutoHide = (state & ABS.Autohide) == ABS.Autohide; 
     } 
    } 

    public enum ABM : uint 
    { 
     New = 0x00000000, 
     Remove = 0x00000001, 
     QueryPos = 0x00000002, 
     SetPos = 0x00000003, 
     GetState = 0x00000004, 
     GetTaskbarPos = 0x00000005, 
     Activate = 0x00000006, 
     GetAutoHideBar = 0x00000007, 
     SetAutoHideBar = 0x00000008, 
     WindowPosChanged = 0x00000009, 
     SetState = 0x0000000A, 
    } 

    public enum ABE : uint 
    { 
     Left = 0, 
     Top = 1, 
     Right = 2, 
     Bottom = 3 
    } 

    public static class ABS 
    { 
     public const int Autohide = 0x0000001; 
     public const int AlwaysOnTop = 0x0000002; 
    } 

    public static class Shell32 
    { 
     [DllImport("shell32.dll", SetLastError = true)] 
     public static extern IntPtr SHAppBarMessage(ABM dwMessage, [In] ref APPBARDATA pData); 
    } 

    public static class User32 
    { 
     [DllImport("user32.dll", SetLastError = true)] 
     public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 
    } 

    [StructLayout(LayoutKind.Sequential)] 
    public struct APPBARDATA 
    { 
     public uint cbSize; 
     public IntPtr hWnd; 
     public uint uCallbackMessage; 
     public ABE uEdge; 
     public RECT rc; 
     public int lParam; 
    } 

    [StructLayout(LayoutKind.Sequential)] 
    public struct RECT 
    { 
     public int left; 
     public int top; 
     public int right; 
     public int bottom; 
    } 
} 

저자는 주장이 자신의 윈도우 7 시스템에서 작동하고 내 XP 프로 시스템에서 작동하도록 나타납니다. 여기

당신이 그것을 사용할 수있는 방법은 다음과 같습니다 tb.Size.Width 및 tb.Size.Height 작업 표시 줄의 폭과 높이를 반환하고 작업 표시 줄 경우 tb.AutoHide가 true를 돌려 :

Taskbar tb = new Taskbar(); 
    Console.WriteLine("w:{0}, h:{1} - hide:{2}", tb.Size.Width, tb.Size.Height, tb.AutoHide); 

숨겨진 경우 false입니다. SPI_GETWORKAREA

1

SystemParametersInfo는 기본 디스플레이 모니터의 작업 영역의 크기를 가져옵니다. 작업 영역은 시스템 작업 표시 줄이나 응용 프로그램 데스크탑 도구 모음에 의해 가려지지 않는 화면 부분입니다. pvParam 매개 변수는 가상 화면 좌표로 표현 된 작업 영역의 좌표를받는 RECT 구조체를 가리켜 야합니다.

기본 디스플레이 모니터 이외의 모니터 작업 영역을 가져 오려면 GetMonitorInfo 함수를 호출하십시오.

0

IsWindowVisible Win32 기능을 사용할 수 있습니다.

[DllImport("user32.dll")] 
    [return: MarshalAs(UnmanagedType.Bool)] 
    static extern bool IsWindowVisible(IntPtr hWnd); 

    IntPtr hWnd = FindWindow("Shell_TrayWnd", null); 
    if (hWnd != null) IsTaskBarVisible = IsWindowVisible(hWnd); 
관련 문제