![](/img/trans.png)
[英]Command Line Arguments wxCmdLineArgsArray in wxWidgets
[英]Command line arguments in wxWidgets
有沒有辦法可以讀取傳遞給C ++ wxWidgets應用程序的命令行參數? 如果是這樣,請您提供一個如何操作的示例。
在普通的C ++中,有argc
和argv
。 在構建wxWidgets應用程序時,可以使用wxApp::argc
, wxApp::argv[]
或wxAppConsole::argc
, wxAppConsole::argv[]
訪問這些應用程序。 請注意, wxApp
派生自wxAppConsole
,因此根據您是否擁有控制台應用程序或GUI應用程序而工作。 請參閱wxAppConsole
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit() {
// Access command line arguments with wxApp::argc, wxApp::argv[0], etc.
// ...
}
您可能也對wxCmdLineParser感興趣。
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;
}
您可以從您訪問命令行變量wxApp
,因為它從inherites wxAppConsole
提供wxAppConsole :: ARGC和wxAppConsole :: argv的 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.