Skip to content
Search

WxLogTextCtrl

lastmod 2015-04-08created 2015-04-082 edits

Prints log messages from wxLogMessage and the like to a Text Widget.

How to use

wxLogTextCtrl has no output capability of its own, so you must pass a pointer to a wxTextCtrl to its constructor. Then register the wxLogTextCtrl using the wxLog::SetActiveTarget() static method.

Simple example

LogMessagePanel::LogMessagePanel(wxWindow * parent
        , wxWindowID id, wxPoint const & pos, wxSize const & size)
        : wxPanel(parent, id, pos, size)
{
    int const kHeight = 150;
    int const kProportion = 1;
    int const kBorder = 5;

    _log_text = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
                wxSize(-1, kHeight), wxTE_MULTILINE | wxTE_READONLY);
    _log_ctrl = new wxLogTextCtrl(_log_text);
    wxLog::SetActiveTarget(_log_ctrl);

    wxBoxSizer * vbox = new wxBoxSizer(wxVERTICAL);
    vbox->Add(_log_text, kProportion, wxEXPAND | wxTOP | wxBOTTOM, kBorder);
    SetSizer(vbox);
}