如何获得使用C#的第三方应用程序的按钮的句柄? [英] How to get the handle of 3rd party application's button using c#?

查看:1417
本文介绍了如何获得使用C#的第三方应用程序的按钮的句柄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成第三方应用程序中的单击事件。作为一个开始我试图模拟计算器点击。下面的代码

I am trying to generate an click event in a third party application. As a start I tried to simulate a click in calculator. Here's the code"

IntPtr hwnd = IntPtr.Zero;
IntPtr hwndChild = IntPtr.Zero;
//Get a handle for the Calculator Application main window
hwnd = FindWindow(null, "Calculator");

hwndChild = FindWindowEx(hwnd, IntPtr.Zero, "Button", "1");

//send BN_CLICKED message
SendMessage(hwndChild, BM_CLICK, IntPtr.Zero, IntPtr.Zero);

不过,使用此代码我没有得到按钮的手感。可能有人帮助,请。有没有其他的方式来模拟在第三方应用程序的按钮点击?

But using this code I am not getting the handle of the button. Could someone help please. Is there any other way to simulate a button click on third party application?

感谢。

推荐答案

它开始工作时,我换成

public const uint BM_CLICK = 0x00F5;

public const uint WM_LBUTTONDOWN = 0x0201; 
public const uint WM_LBUTTONUP = 0x0202;

和使用

SendMessage(buttonHandle, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero); 
SendMessage(buttonHandle, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);

这篇关于如何获得使用C#的第三方应用程序的按钮的句柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆