传递参数:
int xWidth = 100;//传递窗口的大小
int yHeight = 200;
String cmdline;//lpParameters 只支持string类型
TCHAR buf[MAX_SIZE];
_stprintf(buf,_T(“%s %d %d”), language, xWidth, yHeight);
cmdline.format(_T(“%s”), buf);
SHELLEXECUTEINFO sei = { sizeof (SHELLEXECUTEINFO) };
sei.lpFile = appPath.getCStr ();
sei.lpParameters = cmdline.getCStr ();
sei.nShow = SW_SHOWNORMAL;
sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC;
需要启动的窗口:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
int argCount = 0;
CString str1,str2;
LPWSTR cmdline = GetCommandLine();//获取命令行参数
LPWSTR* szArgList = CommandLineToArgvW(cmdline, &argCount);//解析命令行参数
// 如果参数小于1个,直接退出
if (argCount < 1 || argCount > 4)
{
return 0;
}
str1 = szArgList[2];//第三个命令行参数
str2 = szArgList[3];//第四个命令行参数
LocalFree(szArgList);//记得释放
}