获取TaskBar的精确位置和大小

时间:2015-03-29 14:37:25

标签: c# .net winforms

如何在Windows窗体应用程序中准确获取Windows TaskBar的大小(高度)和位置?

1 个答案:

答案 0 :(得分:1)

这是:

[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll", SetLastError = true)]
static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
    public int Left;        // x position of upper-left corner
    public int Top;         // y position of upper-left corner
    public int Right;       // x position of lower-right corner
    public int Bottom;      // y position of lower-right corner
}

如何获取taskbar的位置和大小:

//Get the handle of the task bar
IntPtr TaskBarHandle;
TaskBarHandle = FindWindow("Shell_traywnd", "");

RECT rct;

//Get the taskbar window rect in screen coordinates
GetWindowRect(TaskBarHandle, out rct);