天天看點

擷取工作列大小

實作效果;

  

擷取工作列大小
知識運用:

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);
            }
        }
      

繼續閱讀