Example #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Hooker.MouseHookProcedure = new Hooker.HookProc(MouseHookProc);

            //taskBarHandle为返回的任务栏的句柄
            //Shell_TrayWnd为任务栏的类名
            int taskBarHandle = Hooker.FindWindow("Shell_TrayWnd", null);

            //获得任务栏的区域
            //有一点要注意,函数返回时,taskBarRect包含的是窗口的左上角和右下角的屏幕坐标
            //就是说taskBarRect.Width和taskBarRect.Height是相对于屏幕左上角(0,0)的数值
            //这与c#的Rectangle结构是不同的

            //保存任务栏的矩形区域
            Rectangle taskBarRect = new Rectangle();

            Hooker.GetWindowRect(taskBarHandle, ref taskBarRect);
            this.richTextBox1.Text  = "taskBarRect.Location:" + taskBarRect.Location.ToString() + "\n";
            this.richTextBox1.Text += "taskBarRect.Size:" + taskBarRect.Size.ToString() + "\n\n";

            //构造一个c#中的Rectangle结构
            newTaskBarRect = new Rectangle(
                taskBarRect.X,
                taskBarRect.Y,
                taskBarRect.Width - taskBarRect.X,
                taskBarRect.Height - taskBarRect.Y
                );

            this.richTextBox1.Text += "newTaskBarRect.Location:" + newTaskBarRect.Location.ToString() + "\n";
            this.richTextBox1.Text += "newTaskBarRect.Size:" + newTaskBarRect.Size.ToString();
        }