1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: A sample console (as opposed to GUI) program using wxWidgets
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
26 // for all others, include the necessary headers (this file is usually all you
27 // need because it includes almost all "standard" wxWidgets headers)
33 #include <wx/cmdline.h>
35 // ============================================================================
37 // ============================================================================
39 static const wxCmdLineEntryDesc cmdLineDesc
[] =
41 { wxCMD_LINE_SWITCH
, "h", "help", "show this help message",
42 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
43 { wxCMD_LINE_SWITCH
, "d", "dummy", "a dummy switch" },
44 // ... your other command line options here...
49 int main(int argc
, char **argv
)
51 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
53 wxInitializer initializer
;
56 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
60 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
61 switch ( parser
.Parse() )
64 // help was given, terminating
68 // everything is ok; proceed
69 if (parser
.Found("d"))
71 wxPrintf("Dummy switch was given...\n");
76 wxPrintf("Try to guess the magic number (type 'quit' to escape): ");
77 if ( !wxFgets(input
, WXSIZEOF(input
), stdin
) )
81 input
[wxStrlen(input
) - 1] = 0;
83 if (wxStrcmp(input
, "quit") == 0)
87 if (!wxString(input
).ToLong(&val
))
89 wxPrintf("Invalid number...\n");
94 wxPrintf("You guessed!\n");
96 wxPrintf("Bad luck!\n");
107 // If there were no command-line options supplied, emit a message
108 // otherwise it's not obvious that the sample ran successfully
109 wxPrintf("Welcome to the wxWidgets 'console' sample!\n");
110 wxPrintf("For more information, run it again with the --help option\n");
113 // do something useful here