取任务栏的句柄及相关信息(仅以取任务栏的高度为例)

//怎么得到任务栏的高度?
//仅供参考,不见得是最佳方法
//注意任务栏有可能在边上
// http://ike.126.com/

[DllImport("User32.dll",EntryPoint="FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
 public int Left;
 public int Top;
 public int Right;
 public int Bottom;
}

[DllImport("user32.dll",EntryPoint="GetWindowRect")]
private static extern bool GetWindowRect( IntPtr hWnd, ref RECT lpRect );

private void button1_Click(object sender, System.EventArgs e)
{
 
 IntPtr hWnd = FindWindow ("Shell_TrayWnd",null);
 RECT rc = new RECT();
 try
 {
  GetWindowRect(hWnd,ref rc);
 }
 catch (Exception exp)
 {
  MessageBox.Show(exp.Message);
 }

 Console.WriteLine("Height:{0}",rc.Bottom-rc.Top);
}

 

////////////////
另外一种方法
            Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
屏幕高
            Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
工作区高
相减 应该是任务栏高吧
////////////////
//如此
int a = Screen.PrimaryScreen.WorkingArea.Height;
int b = Screen.PrimaryScreen.Bounds.Height;
Console.WriteLine("{0}",b-a);
///// 

 

posted @ 2008-07-04 14:10  sagamaw  阅读(428)  评论(0编辑  收藏  举报