在MFC程序中,可以用以下几种方法来获取命令行参数。
为方便说明,我们假设执行了命令:C:\test\app.exe -1 -2
方法一
::GetCommandLine();
将获取到 "C:\test\app.exe" -1 -2
方法二
for (int i=0;i<__argc;i++)
{
__argv[i];
将依次得到C:\test\app.exe -1 -2
}
方法三
AfxGetApp()->m_lpCmdLine;
将获取到 -1 -2
为方便说明,我们假设执行了命令:C:\test\app.exe -1 -2
方法一
::GetCommandLine();
将获取到 "C:\test\app.exe" -1 -2
方法二
for (int i=0;i<__argc;i++)
{
__argv[i];
将依次得到C:\test\app.exe -1 -2
}
方法三
AfxGetApp()->m_lpCmdLine;
将获取到 -1 -2
本文详细介绍了在MFC程序中通过三种方法获取命令行参数的技术,包括使用GetCommandLine()函数、for循环遍历__argc和__argv数组以及调用AfxGetApp()->m_lpCmdLine的方法。
3291

被折叠的 条评论
为什么被折叠?



