Gnuplotを操る
http://d.hatena.ne.jp/KrdLab/20060528/1148815875
でもやったけど,今回はC#オンリーで書いてみようかと.
自分の復習を兼ねてます.
Spy++ で調べてみると,コマンド入力ウィンドウのウィンドウクラスは "wgnuplot_text" です.
基本的な方針としては,
- プロセス起動
- プロセスのメインスレッドに関連づけられている親ウィンドウを取得
- 子ウィンドウの中から "wgnuplot_text" を持つウィンドウを検索
- ウィンドウハンドルを取得
- PostMessage を用いて,コマンドを送信
なので,
- Process
- Process.MainWindowHandle
- P/Invoke で FindWindowEx
- ↑
- P/Invoke で PostMessage
となります.
おそらく,一番オーソドックスな方法ではないかと.(2009/01/06 追記:より簡潔な方法は,コメント欄を参照してください)
http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/jpwinui/html/_win32_findwindowex.asp
http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/jpwinui/html/_win32_postmessage.asp
P/Invokeの宣言がまとめてあるサイト → http://www.pinvoke.net/
P/Invokeのサンプル → http://msdn2.microsoft.com/ja-jp/library/fzhhdwae(VS.80).aspx
成果物
(2013/02/05 追記: こちらに移りました → https://github.com/krdlab/wgnuplot4cs)
Wgnuplot(http://krdlab.kakurezato.com/prototype.html)ソースコード(http://krdlab.kakurezato.com/prototype.html)
(興味のある方は,是非改造してください.そして,それを私にください.f^_^; <おい!)
(2008/03/19 配置場所を変えました.)
使い方
- 自分のプロジェクトに Wgnuplot.dll を参照させる
- サンプルみたいに呼び出す
- 自分が作成した実行ファイルと同じフォルダに wgnuplot.exe を配置する
- 実行!
サンプル
namespace KrdLab.Test { class Program { static void Main(string[] args) { using (Wgnuplot plot = new Wgnuplot()) { plot.Send("splot x**2 + y**2"); System.Console.Read(); } } } }
- gnuplotの解説サイト