wxWidgets中的命令行参数 [英] Command line arguments in wxWidgets

查看:498
本文介绍了wxWidgets中的命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法我可以读取传递到C ++ wxWidgets应用程序的命令行参数?

Is there a way I can read the command line arguments passed into a C++ wxWidgets application? If so, could you please provide an example of how to do so.

推荐答案

请查看这些示例( 1 2 )或:

Have a look at these examples (1, 2) or:

int main(int argc, char **argv) 
{ 
    wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program"); 

    wxInitializer initializer; 
    if (!initializer) 
    { 
        fprintf(stderr, "Failed to initialize the wxWidgets library, aborting."); 
        return -1; 
    } 

    static const wxCmdLineEntryDesc cmdLineDesc[] = 
    { 
        { wxCMD_LINE_SWITCH, "h", "help", "show this help message", 
            wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, 
        // ... your other command line options here... 

        { wxCMD_LINE_NONE } 
    }; 

    wxCmdLineParser parser(cmdLineDesc, argc, wxArgv); 
    switch ( parser.Parse() ) 
    { 
        case -1: 
            wxLogMessage(_T("Help was given, terminating.")); 
            break; 

        case 0: 
            // everything is ok; proceed 
            break; 

        default: 
            wxLogMessage(_T("Syntax error detected, aborting.")); 
            break; 
    } 
    return 0; 
}

这篇关于wxWidgets中的命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆