From f1c4b5ae90c30f73f47164eb4f021e38393be5fd Mon Sep 17 00:00:00 2001 From: DYH <1742647821@qq.com> Date: Mon, 20 Jun 2022 05:44:54 +0000 Subject: [PATCH] =?UTF-8?q?add=20src/IFoxCAD.Cad/Runtime/CommandTool.cs.?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0sendcommand=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/IFoxCAD.Cad/Runtime/CommandTool.cs | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/IFoxCAD.Cad/Runtime/CommandTool.cs diff --git a/src/IFoxCAD.Cad/Runtime/CommandTool.cs b/src/IFoxCAD.Cad/Runtime/CommandTool.cs new file mode 100644 index 0000000..bb157c3 --- /dev/null +++ b/src/IFoxCAD.Cad/Runtime/CommandTool.cs @@ -0,0 +1,31 @@ +public static class CommandTool +{ + /// + /// 发送cmd指令 + /// + /// 命令内容 + /// 指示发送的字符串是否在命令行上回显 + internal static void SendCommand(string CommandParameter, bool echoCommand = false) + { + Document mdiActiveDocument = Application.DocumentManager.MdiActiveDocument; + SetFocus(mdiActiveDocument.Window.Handle); + if (mdiActiveDocument == null) + return; + if (CommandParameter.StartsWith("'")) + { + mdiActiveDocument.SendStringToExecute(CommandParameter + "\n", true, false, echoCommand); + } + else + { + string Left = Application.GetSystemVariable("cmdnames").ToString(); + if (Left == "") + mdiActiveDocument.SendStringToExecute("_" + CommandParameter + "\n", true, false, echoCommand); + else if (Left.Length >= 4 && Left.Substring(0, 4).ToUpper() == "GRIP") + mdiActiveDocument.SendStringToExecute("_" + CommandParameter + "\n", true, false, echoCommand); + else + mdiActiveDocument.SendStringToExecute("\u0003\u0003_" + CommandParameter + "\n", true, false, echoCommand); + } + } + [System.Runtime.InteropServices.DllImport("user32.dll")] + private static extern IntPtr SetFocus(IntPtr hwnd); +} \ No newline at end of file -- Gitee