//擷取視窗標題[DllImport("user32", SetLastError = true)]public static extern int GetWindowText( IntPtr hWnd,//視窗控制代碼 StringBuilder lpString,//標題 int nMaxCount //最大值 );//擷取類的名字[DllImport("user32.dll")]private static extern int GetClassName( IntPtr hWnd,//控制代碼 StringBuilder lpString, //類名 int nMaxCount //最大值 );//根據座標擷取視窗控制代碼[DllImport("user32")]private static extern IntPtr WindowFromPoint(Point Point //座標);private void timer1_Tick(object sender, EventArgs e){ int x = Cursor.Position.X; int y = Cursor.Position.Y; Point p = new Point(x, y); IntPtr formHandle = WindowFromPoint(p);//得到視窗控制代碼 StringBuilder title = new StringBuilder(256); GetWindowText(formHandle, title, title.Capacity);//得到視窗的標題 StringBuilder className = new StringBuilder(256); GetClassName(formHandle, className, className.Capacity);//得到視窗的控制代碼 this.textBox1.Text = title.ToString(); this.textBox2.Text = formHandle.ToString(); this.textBox3.Text = className.ToString();}