Mercurial > mercurial > hgweb_console.cgi
changeset 0:dabf2a6b7d4e default tip
wxWidgets minimal console app.
author | pyon@macmini |
---|---|
date | Wed, 12 Feb 2020 21:21:24 +0900 |
parents | |
children | |
files | Makefile console2.cpp |
diffstat | 2 files changed, 130 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Wed Feb 12 21:21:24 2020 +0900 @@ -0,0 +1,46 @@ +# Makefile for wxWidgets Console Application +# Last Change: 2020-02-12 Wed 18:59:56. +# by Takayuki Mutoh +# + +PROGNAME = console2 + +### Variables ### +CXX = g++ +#ARCH = 32 +ARCH = 64 +vpath %.cpp ./src +vpath %.h ./include + +# For Microsoft Windows +ifdef COMSPEC +LOCAL = C:/msys64/home/muto/local$(ARCH) +WXCXXFLAGS = -I$(LOCAL)/lib/wx/include/msw-unicode-static-3.1 -I$(LOCAL)/include/wx-3.1 -D_LARGEFILE_SOURCE=unknown -D__WXMSW__ -mthreads +WXLIBS = -L$(LOCAL)/lib -Wl,--subsystem,windows -mwindows -lwx_mswu_xrc-3.1 -lwx_mswu_qa-3.1 -lwx_baseu_net-3.1 -lwx_mswu_html-3.1 -lwx_mswu_adv-3.1 -lwx_mswu_core-3.1 -lwx_baseu_xml-3.1 -lwx_baseu-3.1 -lwxtiff-3.1 -lwxjpeg-3.1 -lwxpng-3.1 -lwxregexu-3.1 -lwxscintilla-3.1 -lwxexpat-3.1 -lwxzlib-3.1 -lrpcrt4 -loleaut32 -lole32 -luuid -luxtheme -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lcomdlg32 -ladvapi32 -lversion -lwsock32 -lgdi32 -loleacc +LIBS = $(WXLIBS) -static + +EXECUTABLE = $(PROGNAME).exe + +# For Apple OSX +else +WXCXXFLAGS = -I/opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.1/lib/wx/include/osx_cocoa-unicode-3.1 -I/opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.1/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMAC__ -D__WXOSX__ -D__WXOSX_COCOA__ +WXLIBS = -L/opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.1/lib -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -framework OpenGL -lwx_osx_cocoau_xrc-3.1 -lwx_osx_cocoau_html-3.1 -lwx_osx_cocoau_qa-3.1 -lwx_osx_cocoau_adv-3.1 -lwx_osx_cocoau_core-3.1 -lwx_baseu_xml-3.1 -lwx_baseu_net-3.1 -lwx_baseu-3.1 +LIBS = $(WXLIBS) + +EXECUTABLE = $(PROGNAME) + +endif + +CXXFLAGS = $(WXCXXFLAGS) -I./include + +all: $(EXECUTABLE) + strip --strip-all $(EXECUTABLE) + +$(EXECUTABLE): console2.cpp + $(CXX) -o $@ $< $(WXLIBS) $(CXXFLAGS) + +clean: + rm -f $(PROGNAME) $(PROGNAME).exe + +.PHONY: all clean +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/console2.cpp Wed Feb 12 21:21:24 2020 +0900 @@ -0,0 +1,84 @@ +#include "wx/wxprec.h" + +#include <wx/wx.h> +#include <wx/app.h> +#include <wx/cmdline.h> + +static const wxCmdLineEntryDesc cmdLineDesc[] = +{ + { wxCMD_LINE_SWITCH, "h", "help", "show this help message", + wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, + { wxCMD_LINE_SWITCH, "d", "dummy", "a dummy switch", + wxCMD_LINE_VAL_NONE, 0 }, + { wxCMD_LINE_SWITCH, "s", "secret", "a secret switch", + wxCMD_LINE_VAL_NONE, wxCMD_LINE_HIDDEN }, + // ... your other command line options here... + + wxCMD_LINE_DESC_END +}; + +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; + } + + wxCmdLineParser parser(cmdLineDesc, argc, argv); + switch (parser.Parse()) { + case -1: + // help was given, terminating + break; + + case 0: + // everything is ok; proceed + if (parser.Found("d")) { + wxPrintf("Dummy switch was given...\n"); + + while (1) { + wxChar input[128]; + wxPrintf("Try to guess the magic number (type 'quit' to escape): "); + if ( !wxFgets(input, WXSIZEOF(input), stdin) ) + break; + + // kill the last '\n' + input[wxStrlen(input) - 1] = 0; + + if (wxStrcmp(input, "quit") == 0) + break; + + long val; + if (!wxString(input).ToLong(&val)) { + wxPrintf("Invalid number...\n"); + continue; + } + + if (val == 42) + wxPrintf("You guessed!\n"); + else + wxPrintf("Bad luck!\n"); + } + } + if (parser.Found("s")) { + wxPrintf("Secret switch was given...\n"); + } + + break; + + default: + break; + } + + if (argc == 1) { + wxPrintf("Welcome to the wxWidgets 'console' sample!\n"); + wxPrintf("For more information, run it again with the --help option\n"); + } + + // do something useful here + + return 0; +} +