0

I am working on a GUI project in C# Winforms that requires the use of charts from gnuplot. These charts must be in the dynamic form so that the user can get information by clicking on the chart. This means that I have to have the window open and cannot simply use a picture of the chart in the GUI. I have everything working, but I want to be able to control where on screen the gnuplot chart appears so that the user does not have to move it manually. I am using C# processes to run gnuplot and I have found that using the user32.dll function MoveWindow would let me move a window of a process if I had its window handle, but unfortunately the graphs are not the process themselves, they are created by sending commands to gnuplot from the process so I cannot find the window handle of the graph itself.

Is there anyway for me to get the window handle of these graphs, or does anybody know an easier way to choose where graphs created by gnuplot appear on sceen?

Here is some sample code showing how my process is creating the gnuplot graphs

Process gnuPlot = new Process();
        gnuPlot.StartInfo.FileName = programName;
        gnuPlot.StartInfo.UseShellExecute = false;
        gnuPlot.StartInfo.RedirectStandardInput = true;
        gnuPlot.StartInfo.CreateNoWindow = true;
        gnuPlot.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
        gnuPlot.Start();            

        StreamWriter gnuPlotInput = gnuPlot.StandardInput;
        gnuPlotInput.WriteLine("set pm3d map");
        gnuPlotInput.Flush();
        string graphFileName = "fileName" notitle";
        gnuPlotInput.WriteLine(String.Format("splot {0}", graphFileName));
        gnuPlotInput.Flush();

Thanks in Advance,

-Jake

Jake Gearhart
  • 297
  • 7
  • 21
  • Actually I just solved it by finding the handle by searching for the process by the window name. I will post the code later in the off chance that it could help anyone later on. – Jake Gearhart Jul 12 '13 at 04:47

1 Answers1

0

Here is what worked for me in case it helps anyone in the future

IntPtr windowId = IntPtr.Zero;
while (windowId == IntPtr.Zero)//keeps trying to get the id until it has it
     windowId = FindWindowByCaption(IntPtr.Zero, "Gnuplot (window id : 0)");      

MoveWindow(windowId, 670, 100, 550, 400, true);//adjusts the location of the gnuplot window
Jake Gearhart
  • 297
  • 7
  • 21