zl程序教程

您现在的位置是:首页 >  其它

当前栏目

获取任务栏大小

获取 大小 任务栏
2023-09-14 09:00:20 时间

实现效果;

  

知识运用:

API  FindWindow函数  //可用来返回任务栏所在窗口Shell_TrayWnd的句柄

   IpClassName :要返回的窗口的类名称字符串指针

  IpWindowName:要返回的窗口的名称

  GetWindowRect函数  //获取任何一个窗口的矩阵范围的函数

  hwnd:目标窗口的句柄

  IpRect:存储窗口区域的Rectangle结构变量

  

实现代码:

        [DllImport("user32.dll")]
        public static extern int FindWindow(string IpClassName,string IpWindowName);
        [DllImport("user32.dll")]
        public static extern int GetWindowRect(int hwnd,ref Rectangle IpRect);
        Rectangle rect;
        private void button1_Click(object sender, EventArgs e)
        {
            if ((GetWindowRect(FindWindow("Shell_TrayWnd", null), ref rect)) == 0)
                return;
            else
            {
                textBox1.Text = Convert.ToString(rect.Left);
                textBox2.Text = Convert.ToString(rect.Top);
                textBox3.Text = Convert.ToString(rect.Right);
                textBox4.Text = Convert.ToString(rect.Bottom);
            }
        }