主要的过程,日后操作autocad lt也应该可以用此方法主要的过程,日后操作autocad lt也应该可以用此方法1 var pros = Process.GetProcessesByName(acad);2 if (pros.Length == 0)3 {4 MessageBox.Show(没有找到acad进程...
1 var pros = Process.GetProcessesByName("acad"); 2 if (pros.Length == 0) 3 { 4 MessageBox.Show("没有找到acad进程,请检查后再运行本程序!"); 5 return; 6 } 7 SendCommandToAutoCAD("_circle 0,0,0 300 ", pros.First().MainWindowHandle); 8 SetForegroundWindow(pros.First().MainWindowHandle);
导入win32的api的函数
1 [DllImport("user32.dll")] 2 public static extern bool SetForegroundWindow(IntPtr hWnd); 3 4 [DllImport("user32.dll", EntryPoint = "FindWindow")] 5 public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 6 7 [DllImport("user32.dll")] 8 private static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
1 private struct COPYDATASTRUCT 2 { 3 public IntPtr dwData; 4 5 public int cbData; 6 7 public IntPtr lpData; 8 9 }
kean大神提供的向autocad 命令行发送命令的函数
1 private void SendCommandToAutoCAD(string toSend, IntPtr hwnd) 2 { 3 const int WM_COPYDATA = 0x4A; 4 COPYDATASTRUCT cds = new COPYDATASTRUCT(); 5 cds.dwData = new IntPtr(1); 6 string data = toSend + "\0"; 7 cds.cbData = data.Length * Marshal.SystemDefaultCharSize; 8 cds.lpData = Marshal.StringToCoTaskMemAuto(data); 9 SendMessageW(hwnd, WM_COPYDATA, IntPtr.Zero, ref cds); 10 Marshal.FreeCoTaskMem(cds.lpData); 11 }
沃梦达教程
本文标题为:c# autocad 通过进程向cad发送command
基础教程推荐
猜你喜欢
- c# – linux / mono上的HTTP性能 2023-09-19
- vs dotnet core 附加进程调试时有多个dotnet进程,没有title 2023-09-26
- c#中查询表达式GroupBy的使用方法 2023-05-06
- C#中ManualResetEvent实现线程的暂停与恢复 2023-05-16
- C#中对象状态模式教程示例 2023-06-09
- C#使用DoddleReport快速生成报表 2023-06-15
- Unity AssetBundle打包工具示例详解 2023-05-06
- C#设计模式之Singleton模式 2023-02-25
- 在c#中从Windows azure中删除blob 2023-09-19
- C#开发WinForm清空DataGridView控件绑定的数据 2023-05-25