1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/console/console.cpp
3 // Purpose: A sample console (as opposed to GUI) program using wxWidgets
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWidgets headers)
34 #include <wx/cmdline.h>
36 // ============================================================================
38 // ============================================================================
40 static const wxCmdLineEntryDesc cmdLineDesc
[] =
42 { wxCMD_LINE_SWITCH
, "h", "help", "show this help message",
43 wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
44 { wxCMD_LINE_SWITCH
, "d", "dummy", "a dummy switch" },
45 // ... your other command line options here...
50 int main(int argc
, char **argv
)
52 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE
, "program");
54 wxInitializer initializer
;
57 fprintf(stderr
, "Failed to initialize the wxWidgets library, aborting.");
61 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
62 switch ( parser
.Parse() )
65 // help was given, terminating
69 // everything is ok; proceed
70 if (parser
.Found("d"))
72 wxPrintf("Dummy switch was given...\n");
77 wxPrintf("Try to guess the magic number (type 'quit' to escape): ");
78 if ( !wxFgets(input
, WXSIZEOF(input
), stdin
) )
82 input
[wxStrlen(input
) - 1] = 0;
84 if (wxStrcmp(input
, "quit") == 0)
88 if (!wxString(input
).ToLong(&val
))
90 wxPrintf("Invalid number...\n");
95 wxPrintf("You guessed!\n");
97 wxPrintf("Bad luck!\n");
108 // If there were no command-line options supplied, emit a message
109 // otherwise it's not obvious that the sample ran successfully
110 wxPrintf("Welcome to the wxWidgets 'console' sample!\n");
111 wxPrintf("For more information, run it again with the --help option\n");
114 // do something useful here