0

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.

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.

For some reason the FindWindowByCaption function finds the window handle before the window actually exists.

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.

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));

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.

Any suggestions would be helpful

Thanks,

-Jake

Jake Gearhart
  • 297
  • 7
  • 21
  • it's strange that when the window can be able to find via its caption, it should have some `valid Handle` of its own. and your `windowId` should be exactly the wanted `Handle`. – King King Sep 23 '13 at 02:07
  • I am able to make the movement work by using Thread.Sleep() for a certain amount of time, but that is only a temp fix. I need to find a way to identify when the gnuplot window is actually on the screen so I can then move it. – Jake Gearhart Sep 23 '13 at 03:10
  • 1
    @JakeGearhart, I guess, this is a bit too late, but what about trying to see, [if window is visible](http://msdn.microsoft.com/en-us/library/windows/desktop/ms633530%28v=vs.85%29.aspx)? – Gabrielius Dec 09 '14 at 09:11
  • I think I solved this a while ago, or found a different way to do what I wanted. Thanks though. – Jake Gearhart Dec 09 '14 at 14:03

0 Answers0