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);
		}
}
		

猜你喜欢

转载自blog.csdn.net/CXYLVCHF/article/details/111234431
今日推荐