日期:2014-05-17  浏览次数:20870 次

SendMessage 发送按钮点击事件 按钮没响应
c#程序给另一个C#程序发送按钮点击事件的时候按钮是有相应的。
可是给其他的一个第三方程序发送按钮点击事件的时候,按钮就没有相应了。按钮的句柄这些都用spy++查看了,没有问题,有谁知道这可能是什么方面的原因吗?

  string aDir = @"D:\gc\Tonsinsoft\MultiTax\Mtdeclare.exe";
  ProcessStartInfo aStartInfo = new ProcessStartInfo();
  aStartInfo.CreateNoWindow = true;
  aStartInfo.FileName = aDir;
  aStartInfo.UseShellExecute = true;
  aStartInfo.WorkingDirectory = @"D:\gc\Tonsinsoft\MultiTax";
   
  System.Diagnostics.Process.Start(aStartInfo);

  Thread.Sleep(1000);

  ParenthWnd = FindWindow("TLoginDialog", null);

  ////用户名
  ParenthWnd_sub = FindWindowEx(ParenthWnd, EdithWnd, "TRzEdit", "");
  SendMessage(ParenthWnd_sub, WM_SETTEXT, (IntPtr)0, this.txtName.Text.Trim());

  ////密码
  ParenthWnd_sub = FindWindowEx(ParenthWnd, ParenthWnd_sub, "TRzEdit", "");
  SendMessage(ParenthWnd_sub, WM_SETTEXT, (IntPtr)0, this.txtPsw.Text.Trim());

  //确定按钮
  ParenthWnd_sub = FindWindowEx(ParenthWnd, (IntPtr)0, "TRzBitBtn", "登录(&O)");
  SendMessage(ParenthWnd_sub, WM_CLICK, 0, 0);


------解决方案--------------------
用 SPY++ 看看。
------解决方案--------------------
用SPY++进行消息监视,看手动点击按钮和程序模拟时的消息有什么区别?用程序完全按手动点击时发生的消息进行模拟
------解决方案--------------------
vb中需要执行2次,SENDMESSAGE 才可以模拟单击动作。执行一次,只会把焦点落到按纽上面。C#中没尝试过
------解决方案--------------------
按手动点击时查看到的消息ID直接发送0xB01B就可以了,跟 WM_CLICK 消息没有关系,因为那个程序没有处理该消息