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

4

1 回答 1

0

这对我有用,以防将来对任何人有所帮助

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
于 2013-07-12T13:43:30.787 回答