|
一:主进程打开子进程
char chCmdLine[256];
sprintf(chCmdLine," /%d /%d /%d /Class:Quote%d",m_hWnd,1,1,GetCurrentProcessId());// /父窗口句柄 / /是否内嵌打开 /
ShellExecute(NULL, NULL,"子进程名", chCmdLine, NULL, SW_SHOWNORMAL);
二:子进程通过主进程打开的命令行获取主进程句柄
CString sParameter;
for (int i = 1; i < __argc; i++)
{
sParameter = __argv[i];
if(i == 1)
m_ParentHWnd = (HWND)atoi(sParameter.Mid(1));
}
三:子进程将子进程句柄发给主进程
HqLoginMsg loginMsg;
loginMsg.m_nType = 1;
loginMsg.m_hWnd = NULL;
loginMsg.m_hMainWnd = this->m_hWnd;
loginMsg.m_nProcessID = GetCurrentProcessId();
loginMsg.m_nID = 1;
COPYDATASTRUCT data;
data.dwData = WM_COPYDATA_LoginWnd;
data.cbData = sizeof(HqLoginMsg);
data.lpData = &loginMsg;
::SendMessage(m_ParentHWnd,WM_COPYDATA,(WPARAM)m_hWnd,(LPARAM)&data);
四:主进程保存子进程句柄信息
BOOL OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
switch(pCopyDataStruct->dwData)
{
case WM_COPYDATA_LoginWnd:
{
if(m_pHqLoginMsg == NULL)
m_pHqLoginMsg = new HqLoginMsg;
memcpy(m_pHqLoginMsg,pCopyDataStruct->lpData,sizeof(HqLoginMsg));
}
break;
}
return True;
}
[code]原文链接:https://blog.csdn.net/qq_32008381/article/details/78751819[/code] |
|