Mercurial > mercurial > hgweb_console.cgi
comparison console2.cpp @ 0:dabf2a6b7d4e default tip
wxWidgets minimal console app.
author | pyon@macmini |
---|---|
date | Wed, 12 Feb 2020 21:21:24 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:dabf2a6b7d4e |
---|---|
1 #include "wx/wxprec.h" | |
2 | |
3 #include <wx/wx.h> | |
4 #include <wx/app.h> | |
5 #include <wx/cmdline.h> | |
6 | |
7 static const wxCmdLineEntryDesc cmdLineDesc[] = | |
8 { | |
9 { wxCMD_LINE_SWITCH, "h", "help", "show this help message", | |
10 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, | |
11 { wxCMD_LINE_SWITCH, "d", "dummy", "a dummy switch", | |
12 wxCMD_LINE_VAL_NONE, 0 }, | |
13 { wxCMD_LINE_SWITCH, "s", "secret", "a secret switch", | |
14 wxCMD_LINE_VAL_NONE, wxCMD_LINE_HIDDEN }, | |
15 // ... your other command line options here... | |
16 | |
17 wxCMD_LINE_DESC_END | |
18 }; | |
19 | |
20 int main(int argc, char **argv) | |
21 { | |
22 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program"); | |
23 | |
24 wxInitializer initializer; | |
25 if (!initializer) | |
26 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting."); | |
27 return -1; | |
28 } | |
29 | |
30 wxCmdLineParser parser(cmdLineDesc, argc, argv); | |
31 switch (parser.Parse()) { | |
32 case -1: | |
33 // help was given, terminating | |
34 break; | |
35 | |
36 case 0: | |
37 // everything is ok; proceed | |
38 if (parser.Found("d")) { | |
39 wxPrintf("Dummy switch was given...\n"); | |
40 | |
41 while (1) { | |
42 wxChar input[128]; | |
43 wxPrintf("Try to guess the magic number (type 'quit' to escape): "); | |
44 if ( !wxFgets(input, WXSIZEOF(input), stdin) ) | |
45 break; | |
46 | |
47 // kill the last '\n' | |
48 input[wxStrlen(input) - 1] = 0; | |
49 | |
50 if (wxStrcmp(input, "quit") == 0) | |
51 break; | |
52 | |
53 long val; | |
54 if (!wxString(input).ToLong(&val)) { | |
55 wxPrintf("Invalid number...\n"); | |
56 continue; | |
57 } | |
58 | |
59 if (val == 42) | |
60 wxPrintf("You guessed!\n"); | |
61 else | |
62 wxPrintf("Bad luck!\n"); | |
63 } | |
64 } | |
65 if (parser.Found("s")) { | |
66 wxPrintf("Secret switch was given...\n"); | |
67 } | |
68 | |
69 break; | |
70 | |
71 default: | |
72 break; | |
73 } | |
74 | |
75 if (argc == 1) { | |
76 wxPrintf("Welcome to the wxWidgets 'console' sample!\n"); | |
77 wxPrintf("For more information, run it again with the --help option\n"); | |
78 } | |
79 | |
80 // do something useful here | |
81 | |
82 return 0; | |
83 } | |
84 |