前段时间有个需求,就是在winform程序里嵌入外部的exe文件,经过查找资料,最终将外部的exe文件完美的嵌入到了winform窗体里了。
由于之前没怎么用过c#,所以对c#并不是很熟悉,下面我的demo中可能会有从网上荡下来的某个方法,如有侵权,可以联系我,不说了,上代码,代码里有详细的注解:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace 内嵌实验
{
public partial class Form1 : Form
{
private const int GWL_STYLE = (-16);
private const int WS_VISIBLE = 0x10000000;
EventHandler appIdleEvent = null;
Action<object, EventArgs> appIdleAction = null;
Process m_AppProcess;
[DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
public static extern IntPtr SetWindowLongPtr32(HandleRef hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Auto)]
public static extern IntPtr SetWindowLongPtr64(HandleRef hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

本文介绍了如何在C#的Winform应用中嵌入并运行外部的EXE文件,通过示例代码展示了如何使用Windows API进行操作,包括设置窗口样式、调整窗口位置等步骤。
最低0.47元/天 解锁文章
1万+

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



