我想要实现的功能是:
我在使用另外一个应用程序A,A程序我没有源码,A程序中有一个【提交案例】的按钮,我会经常点他我想开发一个小工具,能获取到点击【提交案例】按钮的动作,从而自动记录,点击了多少次。请问高手C#.net怎么实现啊?
我在使用另外一个应用程序A,A程序我没有源码,A程序中有一个【提交案例】的按钮,我会经常点他我想开发一个小工具,能获取到点击【提交案例】按钮的动作,从而自动记录,点击了多少次。请问高手C#.net怎么实现啊?
调试欢乐多
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll ", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll ", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);private void button1_Click(object sender, EventArgs e)
{
string lpszParentClass = "SciCalc"; //整个窗口的类名 string lpszParentWindow = "计算器"; //窗口标题 string lpszClass_Submit = "Button"; //需要查找的Button的类名 string lpszName_Submit = "="; //需要查找的Button的标题 IntPtr ParenthWnd = new IntPtr(0); IntPtr EdithWnd = new IntPtr(0); const int WM_CLICK = 0x00F5; ParenthWnd = FindWindow(lpszParentClass,lpszParentWindow); if (!ParenthWnd.Equals(IntPtr.Zero)) {
EdithWnd = FindWindowEx(ParenthWnd,EdithWnd,lpszClass_Submit,lpszName_Submit); if(!EdithWnd.Equals(IntPtr.Zero)) { int i = 0 ;
if(监控“=”号按钮被点击时)
{ i=i+1 }
} } }
1、你可以使用reflector去试着反编译这个程序,看看是否可以得到源码,如果改程序也是.net编写的,又没有被混淆过,应该可以得到大部分源码。2、你可以这样修改源码,获得你要的效果:
参考自博客:http://www.cnblogs.com/michaelhuwei/archive/2007/06/15/784266.html
先定义一个消息过滤器
/// <summary>
/// 自定义的消息过滤器,必须实现 IMessageFilter 接口
/// </summary>
class myFilter : IMessageFilter
{
const int WM_LBUTTONDOWN = 0x0201;
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_LBUTTONDOWN)
{
Console.WriteLine(Control.FromHandle(m.HWnd).Name);
}
return false;
}
}
在Form中添加该过滤器
private void Form1_Load(object sender, EventArgs e)
{
//为窗体添加消息过滤器
Application.AddMessageFilter(new myFilter());
}
注:msdn 上明确注明,AddMessageFilter 会让系统性能下降,估计其低层是用 SetWindowsHook之类的API.
http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx