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

//怎么得到任务栏的高度?
//仅供参考,不见得是最佳方法
//注意任务栏有可能在边上
// 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);
///// 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值