怎么使应用程序支持命令行吗? 
比如, 
c:\> test.exe abc 启动了test程序, test程序可检测到参数是abc
对我来说,那是相当的困难。~~

解决方案 »

  1.   

    楼上的, 你确定可以??控制台程序, 输入test.exe abc 看看结果吧。。
      

  2.   

    CString strCmdLine=::AfxGetApp()->m_lpCmdLine;
    这就是命令行吧
      

  3.   

    原谅我没有把问题表述清楚。
    char * cmdline = ::GetCommandLine(); 可以返回命令行但是在控制台输入c:\> test.exe abc 会提示“ 找不到abc程序”,,, 丫的,不晓得怎么回事
      

  4.   

    c:\> test.exe -abc  // -abc
      

  5.   

    谢谢, Atomictry(天影)我真是惭愧, 你的方法是对的, 
    说说原理如何?
      

  6.   

    void CWinApp::ParseCommandLine(CCommandLineInfo& rCmdInfo)
    {
    for (int i = 1; i < __argc; i++)
    {
    LPCTSTR pszParam = __targv[i];
    BOOL bFlag = FALSE;
    BOOL bLast = ((i + 1) == __argc);
    if (pszParam[0] == '-' || pszParam[0] == '/')
    {
    // remove flag specifier
    bFlag = TRUE;
    ++pszParam;
    }
    rCmdInfo.ParseParam(pszParam, bFlag, bLast);
    }
    }
    看看它的源码吧.
      

  7.   

    我的原来的错,不一定需要"-"
        char * cmdline = ::GetCommandLine(); 
        char szArg[MAX_PATH] = "";
        char szExe[MAX_PATH] = "";
        sscanf(cmdline, "%s %s", szExe, szArg);  
        if (strcmp(szArg, "abc") == 0)
        {
            CString str;
            str.Format("exe: %s; arg: %s", szExe, szArg);
            AfxMessageBox(str);
        }
    你怎么写入命令行参数的,是不是没有指定exe路径?