Windows タスクバーが非表示になっているかどうかを知る必要があります。これを行う .NET メソッドはないと思います。また、「タスクバーを非表示にして表示する方法」のサンプルをたくさん見つけましたが、探しているものに基づいたものは何も見ていません。私は Windows API に詳しくないので、従来の Windows コードを理解するのは難しいと思います。タスクバーの現在の状態が非表示かどうかを示す記事またはタイプコードを教えてください。C#でコーディングしています。
ありがとう。
Windows タスクバーが非表示になっているかどうかを知る必要があります。これを行う .NET メソッドはないと思います。また、「タスクバーを非表示にして表示する方法」のサンプルをたくさん見つけましたが、探しているものに基づいたものは何も見ていません。私は Windows API に詳しくないので、従来の Windows コードを理解するのは難しいと思います。タスクバーの現在の状態が非表示かどうかを示す記事またはタイプコードを教えてください。C#でコーディングしています。
ありがとう。
winSharp93は、機能しているように見えるヘルパークラス(「タスクバーのサイズ(および位置)を確認する」)を提供します。Win32のSHAppBarMessage関数を使用します。
彼のブログからのコード(マイナーな追加を含む)は次のとおりです。
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;
}
}
著者は、それが彼のWindows 7マシンで動作し、私のXPProマシンで動作するように見えると主張しています。
使用方法は次のとおりです。
Taskbar tb = new Taskbar();
Console.WriteLine("w:{0}, h:{1} - hide:{2}", tb.Size.Width, tb.Size.Height, tb.AutoHide);
ここで、tb.Size.Widthとtb.Size.Heightはタスクバーの幅と高さを返し、tb.AutoHideはタスクバーが非表示の場合はtrueを返し、非表示の場合はfalseを返します。
SPI_GETWORKAREA を使用した SystemParametersInfo
プライマリ ディスプレイ モニターの作業領域のサイズを取得します。作業領域は、システム タスクバーやアプリケーションのデスクトップ ツールバーによって隠されていない画面の部分です。pvParam パラメーターは、仮想画面座標で表される作業領域の座標を受け取る RECT 構造体を指している必要があります。
プライマリ ディスプレイ モニター以外のモニターの作業領域を取得するには、GetMonitorInfo 関数を呼び出します。
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);