예제 #1
0
        /// <summary>指定したウィンドウのタイトルを取得する</summary>
        public static string GetWindowTitle(IntPtr windowHandle)
        {
            StringBuilder title = new StringBuilder(300);

            WindowController2.GetWindowText(windowHandle, title, title.Capacity);

            return(title.ToString());
        }
예제 #2
0
        public static void PrepareAutoProcess()
        {
            AutoCad.vbcom.LoadComObject();

            WindowController2.BringAutoCadToTop();
            AutoCad.Command.Prepare();
            AutoCad.Db.Database.SetFileDialogMode(false);
            AutoCad.Command.CloseLayerManager();
        }
예제 #3
0
        /// <summary>指定したウィンドウのテキストを取得する</summary>
        public static string GetText(IntPtr windowHandle)
        {
            var byteLength = WindowController2.SendMessage(windowHandle, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero).ToInt32();

            var buff = new StringBuilder(byteLength + 1);

            WindowController2.SendMessage(windowHandle, WM_GETTEXT, byteLength + 1, buff);

            return(buff.ToString());
        }
예제 #4
0
        private static IntPtr GetTextWindowHandle()
        {
            var finder = new WindowFinder("AutoCAD LT テキスト ウィンドウ - ", "AutoCAD LT Text Window - ");

            //EnumChildWindowsは指定したウィンドウ配下のコントロール全てを、順にコールバック関数に渡す
            var result = WindowController2.EnumChildWindows(new IntPtr(0), finder.FindChildWindow, 0);

            if (result == 1)
            {
                throw new ApplicationException("AutoCADのTextWindowが見つかりませんでした。");
            }

            return(finder.FoundWindowHandle);
        }
예제 #5
0
        /// <summary>AutoCADのコマンドウィンドウのハンドルを取得する</summary>
        public static IntPtr GetCommandWindowHandle()
        {
            var textWindowHandle = WindowController2.GetTextWindowHandle();

            var finder = new WindowFinder("Marin");

            //EnumChildWindowsは指定したウィンドウ配下のコントロール全てを、順にコールバック関数に渡す
            var result = WindowController2.EnumChildWindows(textWindowHandle, finder.FindChildWindow, 0);

            if (result == 1)
            {
                throw new ApplicationException("AutoCADのCommandWindowが見つかりませんでした。");
            }

            return(finder.FoundWindowHandle);
        }
예제 #6
0
            public static string GetDrawingName()
            {
                var drawingHandles = WindowController2.GetDrawingHandles();

                if (drawingHandles.Count != 0)
                {
                    WindowController2.Maximize(drawingHandles[0]);
                }

                foreach (var handle in drawingHandles)
                {
                    var title = WindowController2.GetWindowTitle(handle);
                    return(Path.GetFileNameWithoutExtension(title));
                }

                return(string.Empty);
            }
예제 #7
0
        /// <summary>MDIの子ウィンドウのうち、最前面のウィンドウハンドルを取得する</summary>
        private static IntPtr GetTopChildHandle(IntPtr windowHandle)
        {
            while (true)
            {
                IntPtr mdiHandle = WindowController2.FindWindowEx(windowHandle, IntPtr.Zero, "MDIClient", null);
                if (mdiHandle == IntPtr.Zero)
                {
                    continue;
                }

                var activeChildHandle = WindowController2.GetWindow(mdiHandle, GW_CHILD);
                if (activeChildHandle == IntPtr.Zero)
                {
                    throw new AutoCadException("MDIの子ウィンドウが見つかりませんでした。");
                }

                return(activeChildHandle);
            }
        }
예제 #8
0
        public static IntPtr GetTopDrawingHandle()
        {
            while (true)
            {
                var    autocadWindowHandle = WindowController2.GetAutoCadHandle();
                IntPtr mdiHandle           = WindowController2.FindWindowEx(autocadWindowHandle, IntPtr.Zero, "MDIClient", null);
                //AutoCadのハンドルをうまくとれない時がある。その時mdiHandleがZeroになる。
                if (mdiHandle == IntPtr.Zero)
                {
                    continue;
                }

                var activeChildHandle = WindowController2.GetWindow(mdiHandle, GW_CHILD);
                if (activeChildHandle == IntPtr.Zero)
                {
                    throw new AutoCadException("MDIの子ウィンドウが見つかりませんでした。");
                }

                return(activeChildHandle);
            }
        }
예제 #9
0
            /// <summary>
            /// EnumChildWindowsメソッドの引数に渡すコールバックメソッド
            /// </summary>
            public int FindChildWindow(IntPtr childWindowHandle, int lParam)
            {
                var title = WindowController2.GetWindowTitle(childWindowHandle);

                if (string.IsNullOrEmpty(this.targetTitle))
                {
                    if (title.Contains(this.jpTitle) || title.Contains(this.enTitle))
                    {
                        this.FoundWindowHandle = childWindowHandle;
                        return(0); //見つかったら処理中止
                    }
                }
                else
                {
                    if (title.Contains(this.targetTitle))
                    {
                        this.FoundWindowHandle = childWindowHandle;
                        return(0); //見つかったら処理中止
                    }
                }

                return(1); //処理続行
            }
예제 #10
0
            public static void Create(string templateName)
            {
                var autocadHandle = WindowController2.GetAutoCadHandle();

                //SendCommandだとテンプレートファイル名を入力するまで処理が帰ってこない
                WindowController2.PostCommand(autocadHandle, 57600); //Ctrl+NキーをAutoCADに送信し、ファイル>新規作成メニューを呼び出す

                //2013だと、新規図面を開くと別のプロンプトが立ち上がるが、
                //開いた瞬間は以前のプロンプトからコマンドを読み取るため、
                //うまく動かない。とりあえずループしてごまかす

                while (true)
                {
                    var result = AutoCad.Status.WaitPrompt("テンプレート ファイル名を入力", "Enter template file name");
                    if (result == Status.EventResult.Prompted)
                    {
                        break;
                    }
                }

                AutoCad.Command.SendLine(templateName);
                AutoCad.Status.WaitFinish();
            }
예제 #11
0
        public static void BringDrawingToTop(IntPtr drawingHandle)
        {
            var currentWindowHandle = WindowController2.GetTopDrawingHandle();

            if (currentWindowHandle == drawingHandle)
            {
                return; //既に最前面に来ていたら抜ける
            }
            var lastBlockTableId = AutoCad.Db.BlockTable.GetModelId();

            WindowController2.BringWindowToTop(drawingHandle);

            //タイミングによってか、図面を切り替えても取得するブロックテーブルが切り替わらないことがあるので、
            //前回のブロックテーブルと違うブロックテーブルを取得できるまでひたすら取得する(5回)。
            for (var i = 0; i < 5; i++)
            {
                var blockTableId = AutoCad.Db.BlockTable.GetModelId();
                System.Threading.Thread.Sleep(100);
                if (lastBlockTableId != blockTableId)
                {
                    break;
                }
            }
        }
예제 #12
0
        public static List <IntPtr> GetDrawingHandles()
        {
            while (true)
            {
                var autocadWindowHandle = WindowController2.GetAutoCadHandle();

                IntPtr mdi = FindWindowEx(autocadWindowHandle, IntPtr.Zero, "MDIClient", null);
                if (mdi == IntPtr.Zero)
                {
                    continue;
                }

                List <IntPtr> childList = new List <IntPtr>();
                IntPtr        child     = WindowController2.GetWindow(mdi, GW_CHILD);
                while (child != IntPtr.Zero)
                {
                    childList.Add(child);

                    child = WindowController2.GetWindow(child, GW_HWNDNEXT);
                }

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

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

                WindowController2.SendCommand(autoCADWindow, command);
            }
예제 #14
0
 /// <summary>指定したウィンドウにコマンドを送る。返事を待たずに次の処理へ移る</summary>
 public static void PostCommand(IntPtr windowHandle, int command)
 {
     WindowController2.PostMessage(windowHandle, WM_COMMAND, new IntPtr(command), IntPtr.Zero);
 }
예제 #15
0
        public static void BringAutoCadToTop()
        {
            var handle = WindowController2.GetAutoCadHandle();

            WindowController2.BringWindowToTop(handle);
        }
예제 #16
0
        public static IntPtr GetPromptHandle()
        {
            var commandWindowHandle = WindowController2.GetCommandWindowHandle();

            return(WindowController2.GetDlgItem(commandWindowHandle, 2));
        }
예제 #17
0
 public static void Maximize(IntPtr windowHandle)
 {
     WindowController2.ShowWindow(windowHandle, SW_MAXIMIZE);
 }