• VC中如何处理命令行参数


    无论是SDI、MDI还是基于Dialog的程序,主类都是继承自CWinApp的。在CWinApp中,有命令行参数的成员变量 - m_lpCmdLine

    m_lpCmdLine 是一个LPTSTR,也就是一个32位的字符串,也就是整个命令行参数(不带应用程序可执行文件的名字)。举例来说,如果应用程序是Hello,那么运行 Hello I am John,此时的m_lpCmdLine就是I am John,得到了这个命令行参数之后,应用程序就可以自己再展开分析了。

    最后附上一段MSDN中有关LPTSTR的解说:

    CWinApp::m_lpCmdLine

    Remarks

    Corresponds to the lpCmdLine parameter passed by Windows to WinMain. Points to a null-terminated string that specifies the command line for the application. Use m_lpCmdLine to access any command-line arguments the user entered when the application was started. m_lpCmdLine is a public variable of type LPTSTR.

    Example

    Code: Select all
    BOOL CMyApp::InitInstance()
    {
       // ...


       //通过判断第一个字符是不是字符串结尾标志来判断是否有命令行参数的输入



       if (m_lpCmdLine[0] == _T('\0'))      {
          // Create a new (empty) document.
          OnFileNew();
       }
       else
       {
          // Open a file passed as the first command line parameter.
          OpenDocumentFile(m_lpCmdLine);
       }
     
       // ...
    }
  • 相关阅读:
    触发器心得
    心得:上下游企业的各自特点和出路
    MySQL 触发器例子(两张表同步增加和删除)
    JQuery动态隐藏和显示DIV
    MySQL 触发器例子(下订单自动减少库存)
    Step By Step(Lua目录)
    客户端服务端
    C#多线程1
    GFS架构分析
    一个简单的Windows Socket可复用框架
  • 原文地址:https://www.cnblogs.com/super119/p/2011331.html
Copyright © 2020-2023  润新知