C# WPF 嵌入第三方exe
2021/4/8 14:25:35
本文主要是介绍C# WPF 嵌入第三方exe,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
启动程序
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);
这篇关于C# WPF 嵌入第三方exe的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-03-01沐雪多租宝商城源码从.NetCore3.1升级到.Net6的步骤
- 2024-11-18微软研究:RAG系统的四个层次提升理解与回答能力
- 2024-11-15C#中怎么从PEM格式的证书中提取公钥?-icode9专业技术文章分享
- 2024-11-14云架构设计——如何用diagrams.net绘制专业的AWS架构图?
- 2024-05-08首个适配Visual Studio平台的国产智能编程助手CodeGeeX正式上线!C#程序员必备效率神器!
- 2024-03-30C#设计模式之十六迭代器模式(Iterator Pattern)【行为型】
- 2024-03-29c# datetime tryparse
- 2024-02-21list find index c#
- 2024-01-24convert toint32 c#
- 2024-01-24Advanced .Net Debugging 1:你必须知道的调试工具