Code: Select all
Console (/SUBSYSTEM:CONSOLE)
Code: Select all
Console (/SUBSYSTEM:CONSOLE)
Code: Select all
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
// Declare the application class
// It derives from wxApp class.
class MyApp: public wxApp
{
public:
// Called on application startup
virtual bool OnInit();
};
// Declare our main frame class
class MyFrame: public wxFrame
{
public:
// Constructor
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
private:
};
// Give wxWidgets the means to create a MyApp object.
// The use of this allows wxWidgets to dynamically create an instance of the
// application object at the appropriate point in wxWidgets initialization.
wxIMPLEMENT_APP(MyApp);
// A wxWidgets application does not have a main procedure; the equivalent is the
// wxApp::OnInit member defined for a class derived from wxApp.
bool MyApp::OnInit()
{
wxLogWindow *log_window = new wxLogWindow(NULL, "Log Window", TRUE, TRUE);
// Doesn't work
log_window->LogText("Hello World\n");
// Start the event loop
return true;
}
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(NULL, wxID_ANY, title, pos, size)
{
}
Code: Select all
#include <wx/wx.h>
class MyLogFrame : public wxFrame
{
public:
MyLogFrame()
: wxFrame(NULL, wxID_ANY, _("Test"))
{
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
wxTextCtrl* logText = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxSize(600, 300), wxTE_MULTILINE|wxTE_READONLY);
sizer->Add(logText, 1, wxEXPAND, 5);
SetSizer(sizer);
wxLog::SetActiveTarget(new wxLogTextCtrl(logText));
}
};
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
(new MyLogFrame())->Show();
wxLogWarning("warning");
wxLogMessage("message");
wxLogError("error");
return true;
}
};
IMPLEMENT_APP(MyApp)
Code: Select all
void App::attachConsole()
{
if (attached_console_) {
return;
}
#ifdef _WIN32
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
attached_console_ = true;
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
}
#endif
}