MFC接收命令行参数的三种方法

时间:2022-11-05 14:32:56

方法一:

CString sCmdline = ::GetCommandLine();  
AfxMessageBox(sCmdline);  

将获取到 "C:\test\app.exe  -1 -2 "

  方法二:

for (int i = 0; i < __argc; i++)  
{  
    __argv[i];  
    AfxMessageBox(__argv[i]);  
  
}  
将依次得到"C:\test\app.exe","-1", "-2"

  方法三:

CString sCmdline = AfxGetApp()->m_lpCmdLine;  
将获取到 "-1 -2 ",AfxGetApp()->m_lpCmdLine 只包含参数。