private static List <string> GetCommandHistories()
            { //WM_GETTEXTを使った方法では、改行を取得できないし新しい行が数行漏れるので、クリップボード経由で取ることにした。
                //処理途中でクリップボードを上書きしちゃうので退避しておいて後で復元する。
                //↓でケアしていない形式をコピーしていた場合は復元されません。
                string format = null;

                string[] formatList = { "AutoCAD-LT15", DataFormats.Text, DataFormats.Bitmap };
                foreach (string f in formatList)
                {
                    if (Clipboard.ContainsData(f))
                    {
                        format = f;
                        break;
                    }
                }

                object backup = Clipboard.GetData(format);

                //コマンドウィンドウのハンドルを取得する
                var commandWindowHandle = WindowController2.GetCommandWindowHandle();

                //コマンドウィンドウに対してコピー命令を発行し、コマンド履歴をクリップボードに入れる。
                //32781(0x800D)は編集(E)→ヒストリーをコピー(H) 時に送られるメッセージ。Spy++で見れる
                WindowController2.SendCommand(commandWindowHandle, 32781);

                string clip;

                //たまにクリップボードのコピーがスカるので、取れるまでループさせる。
                while (true)
                {
                    clip = Clipboard.GetText();

                    if (!string.IsNullOrEmpty(clip))
                    {
                        break;
                    }
                }

                string[] histories = clip.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                if (!string.IsNullOrEmpty(format))
                {
                    Clipboard.SetData(format, backup);
                }

                return(new List <string>(histories));
            }
Exemple #2
0
            //コマンド送信系の処理は、ユーザーが割り込むと処理が止まる可能性がある。
            //その為、Command.Sendの直前に[Esc][Esc]を送信し、コマンド欄をクリアすることを推奨する。

            /// <summary>AutoCADにコマンドを送信する</summary>
            private static void Send(string command)
            {
                IntPtr autoCADWindow = WindowController2.GetAutoCadHandle();

                WindowController2.SendCommand(autoCADWindow, command);
            }