title: GetGuiThreadInfo does not work
body: <p>I am trying to send mouse inputs to a window by clicking on another window. As per <a href="https://stackoverflow.com/questions/11890972/simulating-key-press-with-postmessage-only-works-in-some-applications">Simulating key press with PostMessage only works in some applications?</a>, I am trying to find the correct handle to send the event to. Here is what I have so far:</p>
  
  <pre><code>case WM_LBUTTONDOWN:
    GetCursorPos( reinterpret_cast&lt;POINT *&gt;( &amp;mousePosition ) );  
    hWnd = WindowFromPoint(mousePosition);
    threadID = GetWindowThreadProcessId(otherWindow, &amp;procID);
  
    GetGUIThreadInfo(threadID, &amp;currentWindowGuiThreadInfo);
  
    otherWindow = currentWindowGuiThreadInfo.hwndFocus;
  
    ScreenToClient(hWnd, &amp;mousePosition);
    ClientToScreen(otherWindow, &amp;mousePosition);
    ScreenToClient(otherWindow, &amp;mousePosition);
    dw = MAKELPARAM(mousePosition.x, mousePosition.y);
    PostMessage(otherWindow, WM_LBUTTONDOWN, MK_LBUTTON, dw);             
  
    break;
  </code></pre>
  
  <p>Before, finding this thread I was sending a PostMessage to the handle returned by WindowFromPoint and using Spy++ I could see the messages going through (but this approach only worked for certain windows). But now, the GetGuiThreadInfo returns an error code 87 (The parameter is incorrect). I am setting the currentWindowGuiThreadInfo.cbSize to sizeof(GUITHREADINFO).  Where am I going wrong? Please help.I am using Visual C++, win32 on Windows 7 64-bit and Visual Studio 2010.</p>
  
  <p>Thanks a lot!</p>
  
  <p><strong>EDIT</strong>                    </p>
  
  <p>I am sorry for not answering clearly. Here is a more complete version of the code:</p>
  
  <pre><code>POINT mousePosition;
  DWORD dw, procID, threadID;
  HWND hWnd;
  GUITHREADINFO currentWindowGuiThreadInfo;
  currentWindowGuiThreadInfo.cbSize = sizeof(GUITHREADINFO);
  INPUT Input={0};
  HWND hw;
  int e;
  int xPos, yPos;
  MSLLHOOKSTRUCT *mouseParameters = (MSLLHOOKSTRUCT*)lParam;
  int a = 2;
  if (nCode == HC_ACTION) {
      switch(wParam) {
  
          case WM_LBUTTONDOWN:
  
            GetCursorPos( reinterpret_cast&lt;POINT *&gt;( &amp;mousePosition ) );
            hWnd = WindowFromPoint(mousePosition);
  
            threadID = GetWindowThreadProcessId(otherWindow, &amp;procID); //otherWindow exists and I can see the proper threadID
  
  
            GetGUIThreadInfo(threadID, &amp;currentWindowGuiThreadInfo); //currentWindowGuiThreadInfo returns null for all the handles. The cbSize is 48. But no error is returned. The return value is 1
  
            otherWindow= currentWindowGuiThreadInfo.hwndFocus;
            ScreenToClient(hWnd, &amp;mousePosition);
            ClientToScreen(otherWindow, &amp;mousePosition);
            ScreenToClient(otherWindow, &amp;mousePosition);
            dw = MAKELPARAM(mousePosition.x, mousePosition.y);
  
            PostMessage(otherWindow, WM_LBUTTONDOWN, MK_LBUTTON, dw);
            break;
  </code></pre>