现有一个应用程序Application1,上面有一个Button按钮我如何用我自己的程序去模拟点击按下Button。求实现方法,还有源代码

解决方案 »

  1.   

    FindWindow找到窗体,FindWindowEx找到对应控件
    激活对应窗体,机会对应控件,然后SendKeys.Send("Enter");
      

  2.   

    用API??说真的,API我还不怎么会使用。之前装的msdn又搜索不到相关资料···
    求赐教~
      

  3.   

    [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 );
       }
      

  4.   

    如梦真快……
    xp下可能可以,win7下无效。不过只做例子,已经很明确了。
      

  5.   

    http://www.cnblogs.com/jianu/archive/2010/06/28/1767048.html
    FindWindows("窗体标题")
    SendMessage 发送鼠标左键点击消息
    你需要测出按钮中间位置的坐标
      

  6.   

    Win7的计算机不可以,是因为他的按钮和主窗体不在一个Form里,按钮嵌套在另外的Form里,
    用EnumChildWindows继续查找一层即可。
      

  7.   

    参考《.net 自动化测试》一书吧。

    .net 的方法来处理。
      

  8.   

    1. 如果应用程序是.NET写的,可以用反射模拟实现
    2. 否则需要调用windows api函数
      

  9.   

    人生如梦兄给的代码很有用不过对FindWindowEx这个不是很理解IntPtr hwnd = FindWindowEx(hwndCalc, 0,null, "1");我想找到Button名为"搜索"然后按下代码该怎么写?