C#免注册使用大漠插件实现窗体绑定

时间:2021-09-01
本文章向大家介绍C#免注册使用大漠插件实现窗体绑定,主要包括C#免注册使用大漠插件实现窗体绑定使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

一、引用Ddm.dll

在VS中:项目--添加引用--COM--DM.DLL 这步很关键。

二、注册大漠插件

这是注册DLL到系统的一个方法,注册大漠则调用 AutoRegCom("regsvr32 -s dm.dll");

三、实例化大漠对象

Dm.dmsoft dm = new Dm.dmsoft();

四、调用大漠的方法

命名空间:WindowsFormsApp2 

在窗体下加一个:button1

具体代码如下:

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        Dm.dmsoft dm = new Dm.dmsoft();
        public Form1()
        {
            InitializeComponent();
            AutoRegCom("regsvr32 -s dm.dll");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(dm.Ver());

        }
        static string AutoRegCom(string strCmd)
        {
            string rInfo;
            try
            {
                Process myProcess = new Process();
                ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("cmd.exe");
                myProcessStartInfo.UseShellExecute = false;
                myProcessStartInfo.CreateNoWindow = true;
                myProcessStartInfo.RedirectStandardOutput = true;
                myProcess.StartInfo = myProcessStartInfo;
                myProcessStartInfo.Arguments = "/c " + strCmd;
                myProcess.Start();
                StreamReader myStreamReader = myProcess.StandardOutput;
                rInfo = myStreamReader.ReadToEnd();
                myProcess.Close();
                rInfo = strCmd + "\r\n" + rInfo;
                return rInfo;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

调用:

private void button2_Click(object sender, EventArgs e)
        {
            int hwnd = dm.FindWindow("", "GaugeStudio");//获取标题为“GaugeStudio”的窗体句柄
            _ = dm.BindWindow(hwnd, "dx2", "windows3", "windows", 0);//win10下的后台绑定
            dm.MoveTo(30, 30);//鼠标移动到GaugeStudio窗体的30,30位置
            dm.LeftClick();//鼠标单击左键
        }

原文地址:https://www.cnblogs.com/Fpack/p/15215529.html