C# WPF 嵌入第三方exe

互联网 2021/4/8 14:25:35

启动程序String path = @"C:\Program Files (x86)\Babelbird\Babelbird.exe"; //VusionDTI ImAgenGine_MRDPIntPtr hcalc = IntPtr.Zero; //用以存储目标窗口句柄ProcessStartInfo ps = new ProcessStartInfo();ps.FileName = Environment.ExpandEnvironmentVa…

启动程序

            String path = @"C:\Program Files (x86)\Babelbird\Babelbird.exe"; //VusionDTI  ImAgenGine_MRDP
            IntPtr hcalc = IntPtr.Zero; //用以存储目标窗口句柄
            ProcessStartInfo ps = new ProcessStartInfo();
            ps.FileName = Environment.ExpandEnvironmentVariables(path); //exePath要启动的外部应用程序路径
            proc = Process.Start(ps);

指定容器

            System.Windows.Forms.Panel p = new System.Windows.Forms.Panel();
            WindowsFormsHost host = new WindowsFormsHost();
            host.Child = p;
            grid.Children.Add(host);

获取窗口句柄并操作

            hcalc = FindWindow(null, "xxx客户端");
            SetParent(hcalc, hpanel1);
            SetWindowPos(hcalc, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
            Thread.Sleep(5000);
            mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, 700 * 65536 / 2560, 710 * 65536 / 1440, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 700 * 65536 / 2560, 710 * 65536 / 1440, 0, 0);

调用的win32 API

        const int WM_SYSCOMMAND = 0x0112;
        const int SC_CLOSE = 0xF060;
        const int SC_MINIMIZE = 0xF020;
        const int SC_MAXIMIZE = 0xF030;
        public const uint WM_LBUTTONDOWN = 0x0201;
        public const uint WM_LBUTTONUP = 0x0202;
        const int BM_CLICK = 0xF5;
        const short SWP_NOMOVE = 0X2;
        const short SWP_NOSIZE = 1;
        const short SWP_NOZORDER = 0X4;
        const int SWP_SHOWWINDOW = 0x0040;
        const int MOUSEEVENTF_MOVE = 0x0001; //移动鼠标
        const int MOUSEEVENTF_LEFTDOWN = 0x0002; //模拟鼠标左键按下
        const int MOUSEEVENTF_LEFTUP = 0x0004; //模拟鼠标左键抬起
        const int MOUSEEVENTF_RIGHTDOWN = 0x0008; //模拟鼠标右键按下
        const int MOUSEEVENTF_RIGHTUP = 0x0010; //模拟鼠标右键抬起
        const int MOUSEEVENTF_MIDDLEDOWN = 0x0020; //模拟鼠标中键按下
        const int MOUSEEVENTF_MIDDLEUP = 0x0040; //模拟鼠标中键抬起
        const int MOUSEEVENTF_ABSOLUTE = 0x8000; //标示是否采用绝对坐标

        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName); //主要用于发现外部软件窗口的句柄
        [DllImport("user32.dll", SetLastError = true)]
        private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent); //该api用于嵌入到窗口中运行
        [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
        private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam); //对外部软件窗口发送一些消息(如 窗口最大化、最小化等)
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
        [DllImport("user32.dll")]
        private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
随时随地学软件编程-关注百度小程序和微信小程序
关于找一找教程网

本站文章仅代表作者观点,不代表本站立场,所有文章非营利性免费分享。
本站提供了软件编程、网站开发技术、服务器运维、人工智能等等IT技术文章,希望广大程序员努力学习,让我们用科技改变世界。
[C# WPF 嵌入第三方exe]http://www.zyiz.net/tech/detail-153811.html

上一篇:Asp.Net Core 5 REST API - Step by Step

下一篇:c#的类相关知识(一)

赞(0)

共有 条评论 网友评论

验证码: 看不清楚?
    关注微信小程序
    程序员编程王-随时随地学编程

    扫描二维码或查找【程序员编程王】

    可以随时随地学编程啦!

    技术文章导航 更多>
    扫一扫关注最新编程教程