Attaching a GUI Console in wxWidgets

I am writing a wxWidgets GUI application, but it also uses some console objects.

I need a way to display stdout and access stdin; the best way to do this is to display the console as well as the graphical interface. This can be done if the user starts the program from the command line / shell, etc., but the command line does not open automatically to view stdout when the application starts.

I know this should be possible, because when you start the console application, the console starts automatically. I found one or two solutions that require the Windows API, but unfortunately my code must be cross-platform (I am developing this on Linux).

+4
source share
3 answers

The solution is very simple: use wxStreamToTextRedirector . This allows you to redirect console output to a text control. You can create a separate window for this and paint it as a console. The above link gives an example.

+2
source

If you use Code :: Blocks, in the project properties in the "Building Tasks" section, it is possible to create the project as a console application. When you select this application, the application will be connected to the console.

+1
source

WxWidgets has a macro (wxIMPLEMENT_APP_CONSOLE, wxIMPLEMENT_APP) to display the console (or not). It seems that everything is fine, you can select the desired macro depending on your preprocessor definitions.

class MyApp: public wxApp { public: virtual bool OnInit(); }; #ifdef _DEBUG wxIMPLEMENT_APP_CONSOLE(MyApp); #else wxIMPLEMENT_APP(MyApp); #endif bool MyApp::OnInit() { MainWindow *frame = new MainWindow( TOOLNAME, wxPoint(50, 50), wxSize(600,400) ); frame->Maximize(); ... return true; } 
0
source

Source: https://habr.com/ru/post/1304297/


All Articles