怎么向别的程序发送鼠标点击消息?

shyworm 2004-04-23 02:06:48
或者说怎么用一个程序控制鼠标点击另外一个程序(例如浏览器)的某个位置?
...全文
166 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
whalefish2001 2004-05-02
  • 打赏
  • 举报
回复
那别人的程序要做成 DLL 并且还要提供一个接口。

这样的话,可以实现。

不过,不知道你是不是我所说的那个意思。

还是实现鼠标真实的点击?(叫鼠标动起来)




shyworm 2004-04-30
  • 打赏
  • 举报
回复
Montaque的做法是,两个程序都是自己写的。问题是我想用我的程序点击别人的程序(例如浏览器)。
潜水员2099 2004-04-24
  • 打赏
  • 举报
回复

UP
Montaque 2004-04-24
  • 打赏
  • 举报
回复
App 2, 发送消息
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace AppB
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <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.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(192, 112);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(400, 326);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "App2";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}


[DllImport("user32.dll")]
public static extern Int32 PostMessage(IntPtr hWnd,
Int32 Msg,
Int32 wParam,
Int32 lParam
);

[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String lpClassName , String lpWindowName ) ;

private System.Windows.Forms.Button button1;


public const Int32 WM_USER = 0x400;
public const Int32 WM_KKK =WM_USER+ 123 ;

private void button1_Click(object sender, System.EventArgs e)
{
//find windows
IntPtr app1Handle=FindWindow(null,"APP1");
System.Diagnostics.Debug.Assert(!app1Handle.Equals(IntPtr.Zero));

PostMessage(app1Handle,WM_KKK,0,0);

}

private void Form1_Load(object sender, System.EventArgs e)
{

}


}
}
Montaque 2004-04-24
  • 打赏
  • 举报
回复
给段代码
应用程序1

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace AppA
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form,IMessageFilter
{
/// <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()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "APP1";
this.Load += new System.EventHandler(this.Form1_Load);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
Application.AddMessageFilter(this);
}
public const Int32 WM_USER = 0x400;
public const Int32 WM_KKK =WM_USER+ 123 ;

#region IMessageFilter 成员

public bool PreFilterMessage(ref Message m)
{
// TODO: 添加 Form1.PreFilterMessage 实现
if(m.Msg==WM_KKK)
{
MessageBox.Show("I received a messag from other app" );

return true;
}
return false;
}

#endregion


}
}
HNU 2004-04-23
  • 打赏
  • 举报
回复


学习,哪位能给具体代码?
whalefish2001 2004-04-23
  • 打赏
  • 举报
回复
Montaque(Rain + Man=Rainman) 说的到是种不错的方法,
不过不知道在C#里能不能实现。在vc++里实现没问题。

Montaque 2004-04-23
  • 打赏
  • 举报
回复
直接sendmessage ,调用api,可以自定义一个消息.

另外程序中,实现ImessageFilter ,截获这个消息.
terryxin 2004-04-23
  • 打赏
  • 举报
回复
不明白,你到底是自动的点击,有没有一定的规律性啊,
Jinniu 2004-04-23
  • 打赏
  • 举报
回复
别的程序发送消息可以用消息队列来完成!这么捕获鼠标点击那就看你自己的呢!

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧