title: C++ simulate left mouse click on minimized program
body: <p>I have been searching for a bit about this particular problem I am having, I want to be able to simulate a left mouse click on a program that I am currently attached to.</p>
  
  <p>Right now, I create a thread that checks a database for certain values, and when those values come back (the ones I am looking for), I want to be able to then send a left mouse click in any x,y coord of the program (while minimized).</p>
  
  <p>How can this be done for Windows 7?  Thanks!</p>
  
  <p>EDIT: Here is how I am calling the thread ...</p>
  
  <pre><code>HWND child = GetActiveWindow();
  if ( child == NULL )
  MessageBox(0,"Couldn't get the child hwnd!","",0);
  
  DWORD ID;
  HANDLE thread_check_game = CreateThread ( NULL , 0 , (LPTHREAD_START_ROUTINE) game_check_thread , (LPVOID)child, 0 , &amp;ID ); CloseHandle ( game_check_thread );
  </code></pre>
  
  <p>and then ...</p>
  
  <pre><code>DWORD WINAPI game_check_thread(LPVOID lpParam) {
  
  HWND    Window;
  Window = (HWND)lpParam;
  // ... some other code ...
  // ...
  WORD mouseX = 398;
  WORD mouseY = 398;
  
  
  SendMessage(Window,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(mouseX,mouseY));
  SendMessage(Window, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(mouseX, mouseY));
  Write("Sent Left Click\n");
  
  ExitThread(0);
  return 0;
  }
  </code></pre>