如何模拟在应用程序中按按钮 现有一个应用程序Application1,上面有一个Button按钮我如何用我自己的程序去模拟点击按下Button。求实现方法,还有源代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 FindWindow找到窗体,FindWindowEx找到对应控件激活对应窗体,机会对应控件,然后SendKeys.Send("Enter"); 用API??说真的,API我还不怎么会使用。之前装的msdn又搜索不到相关资料···求赐教~ [DllImport ( "user32.dll", EntryPoint = "FindWindow", SetLastError = true )]private static extern IntPtr FindWindow( string lpClassName, string lpWindowName );[DllImport ( "user32.dll", EntryPoint = "FindWindowEx", SetLastError = true )]private static extern IntPtr FindWindowEx( IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow );[DllImport ( "user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto )]private static extern int SendMessage( IntPtr hwnd, uint wMsg, int wParam, int lParam );[DllImport ( "user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true )]private static extern void SetForegroundWindow( IntPtr hwnd )const uint BM_CLICK = 0xF5; IntPtr hwndCalc = FindWindow ( null, "计算器" ); if ( hwndCalc != IntPtr.Zero ) { IntPtr hwnd = FindWindowEx ( hwndCalc, 0, null, "1" ); SetForegroundWindow ( hwndCalc ); SendMessage (hwnd , BM_CLICK, 0, 0 ); } 如梦真快……xp下可能可以,win7下无效。不过只做例子,已经很明确了。 http://www.cnblogs.com/jianu/archive/2010/06/28/1767048.htmlFindWindows("窗体标题")SendMessage 发送鼠标左键点击消息你需要测出按钮中间位置的坐标 Win7的计算机不可以,是因为他的按钮和主窗体不在一个Form里,按钮嵌套在另外的Form里,用EnumChildWindows继续查找一层即可。 参考《.net 自动化测试》一书吧。用.net 的方法来处理。 1. 如果应用程序是.NET写的,可以用反射模拟实现2. 否则需要调用windows api函数 人生如梦兄给的代码很有用不过对FindWindowEx这个不是很理解IntPtr hwnd = FindWindowEx(hwndCalc, 0,null, "1");我想找到Button名为"搜索"然后按下代码该怎么写? Windows系统上,如何实现在远程PC上弹出一个提示框? C# 中如何判断远程文件是否存在? 关于QQ截屏后图片显示的问题 WinForm环境下,添加背景音乐 autocad问题 为什么我的C#程序在安装了.net framework下仍不能正常运行? 好心人帮忙插入段代码 有没有人有整个.net frame的类继承关系的图阿 Win32_ServerConnection 得到的ComputerName 怎么转成IP地址格式 C#程序小问题 水晶报表两个字段和相加 如何探测局域网上计算机是否在线?
激活对应窗体,机会对应控件,然后SendKeys.Send("Enter");
求赐教~
private static extern IntPtr FindWindow( string lpClassName, string lpWindowName );
[DllImport ( "user32.dll", EntryPoint = "FindWindowEx", SetLastError = true )]
private static extern IntPtr FindWindowEx( IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow );
[DllImport ( "user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto )]
private static extern int SendMessage( IntPtr hwnd, uint wMsg, int wParam, int lParam );
[DllImport ( "user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true )]
private static extern void SetForegroundWindow( IntPtr hwnd )
const uint BM_CLICK = 0xF5;
IntPtr hwndCalc = FindWindow ( null, "计算器" );
if ( hwndCalc != IntPtr.Zero )
{
IntPtr hwnd = FindWindowEx ( hwndCalc, 0, null, "1" );
SetForegroundWindow ( hwndCalc );
SendMessage (hwnd , BM_CLICK, 0, 0 );
}
xp下可能可以,win7下无效。不过只做例子,已经很明确了。
FindWindows("窗体标题")
SendMessage 发送鼠标左键点击消息
你需要测出按钮中间位置的坐标
用EnumChildWindows继续查找一层即可。
用
.net 的方法来处理。
2. 否则需要调用windows api函数