C++ MFC中嵌入第三方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,
NULL,
FALSE,
0,
NULL,
NULL,
&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;
SetWindowLong(hwnd, GWL_STYLE, style);
::SetWindowPos(hwnd, HWND_TOP, rect.left, rect.top, rect.Width(), rect.Height(), SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS);
::ShowWindow(hwnd, SW_SHOW);
}
}