[DllImport("user32.dll", EntryPoint="WindowFromPoint")]
public static extern int WindowFromPoint (
int xPoint,
int yPoint
);
  xPoint ---------  Long,x点值  yPoint ---------  Long,y点值[DllImport("user32.dll", EntryPoint="GetWindowText")]
public static extern int GetWindowText (
int hwnd,
string lpString,
int cch
); 
hwnd -----------  Long,欲获取文字的那个窗口的句柄  lpString -------  String,预定义的一个缓冲区,至少有cch+1个字符大小;随同窗口文字载入  cch ------------  Long,lpString缓冲区的长度

解决方案 »

  1.   

    我有一个代码段,你可以参考一下:using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace WindowFromPointApp
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.TextBox textBox2;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.label1 = new System.Windows.Forms.Label();
    this.label2 = new System.Windows.Forms.Label();
    this.label3 = new System.Windows.Forms.Label();
    this.textBox1 = new System.Windows.Forms.TextBox();
    this.textBox2 = new System.Windows.Forms.TextBox();
    this.SuspendLayout();
    // 
    // label1
    // 
    this.label1.Location = new System.Drawing.Point(16, 16);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(128, 23);
    this.label1.TabIndex = 0;
    this.label1.Text = "鼠标下的窗体:";
    // 
    // label2
    // 
    this.label2.Location = new System.Drawing.Point(16, 56);
    this.label2.Name = "label2";
    this.label2.Size = new System.Drawing.Size(56, 23);
    this.label2.TabIndex = 1;
    this.label2.Text = "句柄:";
    // 
    // label3
    // 
    this.label3.Location = new System.Drawing.Point(16, 88);
    this.label3.Name = "label3";
    this.label3.Size = new System.Drawing.Size(48, 23);
    this.label3.TabIndex = 2;
    this.label3.Text = "标题:";
    // 
    // textBox1
    // 
    this.textBox1.Location = new System.Drawing.Point(88, 56);
    this.textBox1.Name = "textBox1";
    this.textBox1.TabIndex = 5;
    this.textBox1.Text = "textBox1";
    // 
    // textBox2
    // 
    this.textBox2.Location = new System.Drawing.Point(88, 88);
    this.textBox2.Name = "textBox2";
    this.textBox2.Size = new System.Drawing.Size(168, 21);
    this.textBox2.TabIndex = 6;
    this.textBox2.Text = "textBox2";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(264, 122);
    this.Controls.Add(this.textBox2);
    this.Controls.Add(this.textBox1);
    this.Controls.Add(this.label3);
    this.Controls.Add(this.label2);
    this.Controls.Add(this.label1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } [System.Runtime.InteropServices.DllImportAttribute("User32.dll")]
    private static extern IntPtr WindowFromPoint(Point point); [System.Runtime.InteropServices.DllImport("User32.Dll")]
    public static extern void GetWindowText(IntPtr h, System.Text.StringBuilder Text, int nMaxCount); private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    IntPtr ptr = WindowFromPoint(Cursor.Position);
    if (ptr != IntPtr.Zero && ptr != this.Handle)
    {
    System.Text.StringBuilder formText = new System.Text.StringBuilder(100);
    GetWindowText(ptr, formText, 100);
    this.Text = formText + Cursor.Position.ToString();
    this.textBox1.Text = ptr.ToString();
    this.textBox2.Text = formText.ToString();
    }
    }
    }
    }
      

  2.   

    参见:
    User32.libBOOL SetCursorPos(          int X,
        int Y
    );//或Currsor.Location = new Point(int x, int y);
      

  3.   

    谢谢 hbxtlhx(踏雪寻岩)
    但是我把鼠标移动到一个menu上面比如IE的menu,就不可以取到上面的字了
      

  4.   

    用WindowFromPoint 只能取到属于窗口类型的Title,并不能取到所有的显示的文字.如果要这样,你要用到好多的API,不好做的.只有WindowFromPoint就做不到了.
      

  5.   

    你可以在CSDN进行全文搜索"屏幕取词"来得到更多的帮助.