Ejemplo n.º 1
0
            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));
            }
Ejemplo n.º 2
0
        public static IntPtr GetPromptHandle()
        {
            var commandWindowHandle = WindowController2.GetCommandWindowHandle();

            return(WindowController2.GetDlgItem(commandWindowHandle, 2));
        }