C++ MFC中嵌入第三方Exe应用程序

C++ MFC中嵌入第三方Exe应用程序

//窗口控件中嵌入第三方exe程序
HANDLE StartProcess(LPCTSTR program, LPCTSTR args)
{
	HANDLE hProcess = NULL;
	PROCESS_INFORMATION processInfo;
	STARTUPINFO startupInfo;
	::ZeroMemory(&startupInfo, sizeof(startupInfo));
	startupInfo.cb = sizeof(startupInfo);
	if (::CreateProcess(program, (LPTSTR)args,
		NULL,  // process security
		NULL,  // thread security
		FALSE, // no inheritance
		0,     // no startup flags
		NULL,  // no special environment
		NULL,  // default startup directory
		&startupInfo,
		&processInfo))
		return hProcess;

	return hProcess;
}
void RunThirdExe()
{
	   HANDLE handle = StartProcess("D:\\Program Files (x86)\\Pure Codec\\x64\\PotPlayerMini64.exe", "");
		UpdateData(TRUE);
		HWND hwnd = NULL;
		CRect rect;
		GetDlgItem(IDC_VIDEO)->GetWindowRect(&rect);
		ScreenToClient(&rect);
		while (!hwnd)
		{
			hwnd = ::FindWindow("PotPlayer64", "PotPlayer");
		}

		if (hwnd)
		{
			::SetParent(hwnd, this->m_hWnd);
			DWORD style = GetWindowLong(hwnd, GWL_STYLE);
			style &= ~WS_CAPTION;//取消标题栏
			style &= ~WS_THICKFRAME;//取消拖动改变大小
			style &= ~WS_MINIMIZEBOX;
			style &= ~WS_MAXIMIZEBOX;
			style |= WS_CHILD;//属性必须设为WS_CHILD
			SetWindowLong(hwnd, GWL_STYLE, style);

			//::MoveWindow(hwnd, rect.left, rect.top, rect.Width(), rect.Height(), true); //将外部程序移到自自身窗口里
			::SetWindowPos(hwnd, HWND_TOP, rect.left, rect.top, rect.Width(), rect.Height(), SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS);//设置嵌入到窗口中的位置
			::ShowWindow(hwnd, SW_SHOW);
		}
}
		
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值