title: How to send a string to other application including Microsoft Word
body: <p>I was trying to accomplish this but did not get good results. I used GetForegroundWindow(), AttachThreadInput(uint,uint,bool) and GetFocus() functions to send the strings to another window. It works with Notepad, Wordpad and other applications, but not with Microsoft Word.</p>
  
  <pre><code>int foregroundWindowHandle = GetForegroundWindow();
  uint remoteThreadId = GetWindowThreadProcessId(foregroundWindowHandle, 0);
  uint currentThreadId = GetCurrentThreadId();
  bool b = AttachThreadInput(remoteThreadId, currentThreadId, true);
  int focused = GetFocus();
  int d = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
  b = AttachThreadInput(remoteThreadId, currentThreadId, false);
  SendMessage(focused , WM_GETTEXT, builder.Capacity, builder);
  clip = builder.ToString();
  
  //Text operations...
  
  SendMessage(focused, WM_SETTEXT, 0, builder);
  </code></pre>
  
  <p>That's the code I have, but it doesn't work with Word. I know that Word uses Custom Controls, but I think there should be another way to handle this.</p>
  
  <p>For example:
  Windows Speech Recognition sends text to every application which has focus even if it is Word. I don't think they made the inputs manually.</p>
  
  <p>I thought to use the SendInputs function but I don't know how to make that.</p>