日期:2014-05-18  浏览次数:20763 次

SendMessage的问题
[DllImport("User32.dll")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 
public const int WM_KEYDOWN = 0x0100;

  private void timer11_Tick(object sender, EventArgs e)
  {
   
  IntPtr calculatorHandle1 = FindWindow(null, "无标题 - 记事本");
  if (calculatorHandle == IntPtr.Zero)
  {
  MessageBox.Show("Application is not running.");
  return;
  }
  SendMessage(calculatorHandle1, WM_KEYDOWN, 49/* 数字键1 */, 0);
  }

为什么无法实现按键消息呢?

------解决方案--------------------
发WM_CHAR试试
------解决方案--------------------
问题在于,你是向主窗口发送消息,calculatorHandle1并不是指向的编辑框的句柄.