[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缓冲区的长度
解决方案 »
- 初次学习C#,在练习switch语句时遇到了问题,请求帮助
- 求一正则表达式
- 一般大家讨论‘打洞’技术的都是A和B之间传输数据包,有没有可能实现A、B、C....N 之间互通?
- 求助!继承自System.Web.UI.Page类中使用 session 遇到的问题
- Microsoft.Jet.OLEDB.4.0[奇怪问题]跪求高手帮忙解决!
- 请教几个录入的问题,谢谢~!!
- 如何把64进制转化位2进制?各位高手帮帮我
- 用C#如何取得机器的MAC地址?
- Icon a=new Icon("tx.ico")这个出错,说找不到tx.ico文件,但我已经添加到解决方案里了呀
- 如何把string转成blob类型,如何把blob类型存为SQLSERVER的image类型,又如何取出来
- 代碼公布:上次公布了一個畫圖的類,但BUG多,功能少.經過一個周未的修改加了部分功能.要的進
- C#入门级别问题,望给予指导!
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();
}
}
}
}
User32.libBOOL SetCursorPos( int X,
int Y
);//或Currsor.Location = new Point(int x, int y);
但是我把鼠标移动到一个menu上面比如IE的menu,就不可以取到上面的字了