需求:
通过自启动多个CAD应用程序,对其进行管理,针对不同CAD程序发送不同命令。
核心功能
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StartAndSendMessageCAD
{
public class WindowsHandleAndProcess
{
//SendMessage参数
private const int WM_KEYDOWN = 0X100;
private const int WM_KEYUP = 0X101;
private const int WM_SYSCHAR = 0X106;
private const int WM_SYSKEYUP = 0X105;
private const int WM_SYSKEYDOWN = 0X104;
private const int WM_CHAR = 0X102;
public int ProcessId = 0;
public IntPtr WindowHandle = IntPtr.Zero;
const int MW_CLOSE = 0x0010;
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);
public delegate bool EnumThreadWindowsCallback(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int processId);
[DllImport("user32.dll")]
public static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("User32.dll", CharSet

本文介绍了一种通过启动并管理多个CAD应用程序的方法,并能够针对不同的CAD程序发送特定命令。利用C#实现获取指定进程下的窗口句柄,进一步实现向CAD程序发送字符串指令。

326

被折叠的 条评论
为什么被折叠?



