Version: 3.3.0
wxMessageOutput Class Referenceabstract

#include <wx/msgout.h>

+ Inheritance diagram for wxMessageOutput:

Detailed Description

Simple class allowing to write strings to various output channels.

wxMessageOutput is a low-level class and doesn't provide any of the conveniences of wxLog. It simply allows writing a message to some output channel: usually file or standard error but possibly also a message box. While use of wxLog and related functions is preferable in many cases sometimes this simple interface may be more convenient.

This class itself is an abstract base class for various concrete derived classes:

It also provides access to the global message output object which is created by wxAppTraits::CreateMessageOutput() which creates an object of class wxMessageOutputStderr in console applications and wxMessageOutputBest in the GUI ones but may be overridden in user-defined traits class.

Example of using this class:

wxMessageOutputDebug().Printf("name=%s, preparing to greet...", name);
wxMessageOutput::Get()->Printf("Hello, %s!", name);
Output messages to the system debug output channel.
Definition: msgout.h:165
void Printf(const wxString &format,...)
Output a message.
static wxMessageOutput * Get()
Return the global message output object.

Library:  wxBase
Category:  Logging

Public Member Functions

void Printf (const wxString &format,...)
 Output a message. More...
virtual void Output (const wxString &str)=0
 Method called by Printf() to really output the text. More...

Static Public Member Functions

static wxMessageOutputGet ()
 Return the global message output object. More...
static wxMessageOutputSet (wxMessageOutput *msgout)
 Sets the global message output object. More...

Member Function Documentation

◆ Get()

static wxMessageOutput* wxMessageOutput::Get ( )

Return the global message output object.

This object is never nullptr while the program is running but may be nullptr during initialization (before wxApp object is instantiated) or shutdown.(after wxApp destruction).

See also

◆ Output()

virtual void wxMessageOutput::Output ( const wxString str)
pure virtual

Method called by Printf() to really output the text.

This method is overridden in various derived classes and is also the one you should override if you implement a custom message output object.

It may also be called directly instead of Printf(). This is especially useful when outputting a user-defined string because it can be simply called with this string instead of using

msgout.Printf("%s", str);

(notice that passing user-defined string to Printf() directly is, of course, a security risk).

◆ Printf()

void wxMessageOutput::Printf ( const wxString format,

Output a message.

This function uses the same conventions as standard printf().

◆ Set()

static wxMessageOutput* wxMessageOutput::Set ( wxMessageOutput msgout)

Sets the global message output object.

Using this function may be a simpler alternative to changing the message output object used for your program than overriding wxAppTraits::CreateMessageOutput().

Remember to delete the returned pointer or restore it later with another call to Set().