MFC启动其他MFC进程,并传递参数,同时获取参数

来源:互联网 发布:thinkpad8 win10优化 编辑:程序博客网 时间:2024/05/17 01:36

启动另外进程采用ShellExecuteEx()函数实现:

SHELLEXECUTEINFO shell = { sizeof(shell) };
 shell.fMask = SEE_MASK_FLAG_DDEWAIT;
 shell.lpVerb = L"open";
 shell.lpFile = L"C:/Users/zs/Desktop/mfc获取命令行参数/receiveparam/Debug/receiveparam.exe";//欲启动进程路径 此处因为测试,我使用绝对路径
 shell.nShow = SW_NORMAL;
 shell.lpParameters = L"hello";//传递参数
 BOOL ret = ShellExecuteEx(&shell);

 

另一个进程要获取传递参数,有多种方法:

1,使用GetCommandLine()函数

 CString str = GetCommandLine();
 MessageBox(str);

 此种方法得到字符串中包含本程序路径

2,使用theApp.m_lpCmdLine

 MessageBox(theApp.m_lpCmdLine);

此种方法得到路径很干净,只有所传递参数。

0 0