title: FindWindowByCaption function finding window handle that doesn't exist yet
body: <p>I am writing a C# application that requires moving gnuplot graphs to specific positions on the user's screen. To do this I am using DllImport to bring in several functions into my program. Specifically FindWindowByCaption and MoveWindow and a few others. This has been working fine for me thus far, but suddenly the graphs have stopped moving.</p>
  
  <p>I figured out that the graphs are taking longer to generate and it tries to execute the MoveWindow function before the window is created so the window is not actually moved. I am not sure why this is a problem now because it was fine in earlier versions of the code.</p>
  
  <p>For some reason the FindWindowByCaption function finds the window handle before the window actually exists.</p>
  
  <p>I have the find window function in a loop that is supposed to try to execute until it finds the proper handle. The name changes for each graph.</p>
  
  <pre><code>IntPtr windowId = IntPtr.Zero;
          while (windowId == IntPtr.Zero)//keeps trying to get the id until it has it
              windowId = FindWindowByCaption(IntPtr.Zero, "p " + polyValue + " s " + (dataLocation + 1));
  </code></pre>
  
  <p>For some reason it finds the handle for the gnuplot graph before it actually is created and then it tries to run the MoveWindow function too soon, so that when the graph is actually generated it does not go to the right place.</p>
  
  <p>Any suggestions would be helpful</p>
  
  <p>Thanks,</p>
  
  <p>-Jake</p>