]> git.saurik.com Git - wxWidgets.git/blame - samples/console/console.cpp
Don't use GetThreadId() in wxMSW code.
[wxWidgets.git] / samples / console / console.cpp
CommitLineData
37667812
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: samples/console/console.cpp
f6c9f2ed 3// Purpose: A sample console (as opposed to GUI) program using wxWidgets
37667812
VZ
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 04.10.99
7// RCS-ID: $Id$
8// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
3fdcd5d5 9// Licence: wxWindows licence
37667812
VZ
10/////////////////////////////////////////////////////////////////////////////
11
e87271f3
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
ce00f59b 19
81ec0e15
FM
20// For compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
ce00f59b 22
81ec0e15 23#ifdef __BORLANDC__
d31b7b68
VZ
24 #pragma hdrstop
25#endif
26
81ec0e15
FM
27// for all others, include the necessary headers (this file is usually all you
28// need because it includes almost all "standard" wxWidgets headers)
29#ifndef WX_PRECOMP
30 #include "wx/wx.h"
31f6de22 31#endif
f6bcfd97 32
81ec0e15
FM
33#include <wx/app.h>
34#include <wx/cmdline.h>
35
e87271f3
VZ
36// ============================================================================
37// implementation
38// ============================================================================
39
81ec0e15 40static const wxCmdLineEntryDesc cmdLineDesc[] =
297ebe6b 41{
81ec0e15
FM
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...
f6bcfd97 46
81ec0e15
FM
47 { wxCMD_LINE_NONE }
48};
89e60357 49
81ec0e15 50int main(int argc, char **argv)
3a994742 51{
81ec0e15 52 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
3a994742 53
81ec0e15
FM
54 wxInitializer initializer;
55 if ( !initializer )
3a994742 56 {
81ec0e15
FM
57 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
58 return -1;
3a994742 59 }
8193a0bd 60
81ec0e15
FM
61 wxCmdLineParser parser(cmdLineDesc, argc, argv);
62 switch ( parser.Parse() )
07a56e45 63 {
81ec0e15
FM
64 case -1:
65 // help was given, terminating
07a56e45
VZ
66 break;
67
81ec0e15
FM
68 case 0:
69 // everything is ok; proceed
70 if (parser.Found("d"))
07a56e45 71 {
81ec0e15 72 wxPrintf("Dummy switch was given...\n");
07a56e45 73
81ec0e15 74 while (1)
07a56e45 75 {
81ec0e15
FM
76 wxChar input[128];
77 wxPrintf("Try to guess the magic number (type 'quit' to escape): ");
78 if ( !wxFgets(input, WXSIZEOF(input), stdin) )
07a56e45 79 break;
b92fd37c 80
81ec0e15
FM
81 // kill the last '\n'
82 input[wxStrlen(input) - 1] = 0;
ce00f59b 83
81ec0e15
FM
84 if (wxStrcmp(input, "quit") == 0)
85 break;
b92fd37c 86
81ec0e15
FM
87 long val;
88 if (!wxString(input).ToLong(&val))
89 {
90 wxPrintf("Invalid number...\n");
91 continue;
92 }
8e907a13 93
81ec0e15
FM
94 if (val == 42)
95 wxPrintf("You guessed!\n");
96 else
97 wxPrintf("Bad luck!\n");
b92fd37c 98 }
b92fd37c 99 }
9d9b7755
VZ
100 break;
101
81ec0e15 102 default:
ec0e0939 103 break;
30ccbb89 104 }
8193a0bd 105
1719a200
VZ
106 if ( argc == 1 )
107 {
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");
112 }
113
81ec0e15 114 // do something useful here
5ba95b79 115
37667812
VZ
116 return 0;
117}