added (and documented) wxSafeShowMessage, use it in wxLogFatalError instead of wxMessageBox
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15466 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -180,6 +180,7 @@ the corresponding topic.
|
||||
\helpref{wxResourceRegisterBitmapData}{registerbitmapdata}\\
|
||||
\helpref{wxResourceRegisterIconData}{wxresourceregistericondata}\\
|
||||
\helpref{wxRmdir}{wxrmdir}\\
|
||||
\helpref{wxSafeShowMessage}{wxsafeshowmessage}\\
|
||||
\helpref{wxSafeYield}{wxsafeyield}\\
|
||||
\helpref{wxSetClipboardData}{wxsetclipboarddata}\\
|
||||
\helpref{wxSetCursor}{wxsetcursor}\\
|
||||
@@ -3168,6 +3169,32 @@ trace masks.
|
||||
\item wxTraceOleCalls: trace OLE method calls (Win32 only)
|
||||
\end{itemize}
|
||||
|
||||
\membersection{::wxSafeShowMessage}\label{wxsafeshowmessage}
|
||||
|
||||
\func{void}{wxSafeShowMessage}{\param{const wxString\& }{title}, \param{const wxString\& }{text}}
|
||||
|
||||
This function shows a message to the user in a safe way and should be safe to
|
||||
call even before the application has been initialized or if it is currently in
|
||||
some other strange state (for example, about to crash). Under Windows this
|
||||
function shows a message box using a native dialog instead of
|
||||
\helpref{wxMessageBox}{wxmessagebox} (which might be unsafe to call), elsewhere
|
||||
it simply prints the message to the standard output using the title as prefix.
|
||||
|
||||
\wxheading{Parameters}
|
||||
|
||||
\docparam{title}{The title of the message box shown to the user or the prefix
|
||||
of the message string}
|
||||
|
||||
\docparam{text}{The text to show to the user}
|
||||
|
||||
\wxheading{See also}
|
||||
|
||||
\helpref{wxLogFatalError}{wxlogfatalerror}
|
||||
|
||||
\wxheading{Include files}
|
||||
|
||||
<wx/log.h>
|
||||
|
||||
\membersection{::wxSysErrorCode}\label{wxsyserrorcode}
|
||||
|
||||
\func{unsigned long}{wxSysErrorCode}{\void}
|
||||
|
@@ -476,11 +476,13 @@ private:
|
||||
|
||||
// return the last system error code
|
||||
WXDLLEXPORT unsigned long wxSysErrorCode();
|
||||
|
||||
// return the error message for given (or last if 0) error code
|
||||
WXDLLEXPORT const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// define wxLog<level>
|
||||
// -------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define DECLARE_LOG_FUNCTION(level) \
|
||||
extern void WXDLLEXPORT wxVLog##level(const wxChar *szFormat, \
|
||||
@@ -559,6 +561,10 @@ DECLARE_LOG_FUNCTION2(SysError, long lErrCode);
|
||||
inline void wxLogTrace(const wxChar *, const wxChar *, ...) { }
|
||||
#endif // debug/!debug
|
||||
|
||||
// wxLogFatalError helper: show the (fatal) error to the user in a safe way,
|
||||
// i.e. without using wxMessageBox() for example because it could crash
|
||||
extern void wxSafeShowMessage(const wxString& title, const wxString& text);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// debug only logging functions: use them with API name and error code
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -588,4 +594,3 @@ DECLARE_LOG_FUNCTION2(SysError, long lErrCode);
|
||||
|
||||
#endif // _WX_LOG_H_
|
||||
|
||||
// vi:sts=4:sw=4:et
|
||||
|
@@ -159,17 +159,22 @@ IMPLEMENT_LOG_FUNCTION(Message)
|
||||
IMPLEMENT_LOG_FUNCTION(Info)
|
||||
IMPLEMENT_LOG_FUNCTION(Status)
|
||||
|
||||
void wxSafeShowMessage(const wxString& title, const wxString& text)
|
||||
{
|
||||
#ifdef __WINDOWS__
|
||||
::MessageBox(NULL, text, title, MB_OK | MB_ICONSTOP);
|
||||
#else
|
||||
wxFprintf(stderr, _T("%s: %s\n"), title.c_str(), text.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
// fatal errors can't be suppressed nor handled by the custom log target and
|
||||
// always terminate the program
|
||||
void wxVLogFatalError(const wxChar *szFormat, va_list argptr)
|
||||
{
|
||||
wxVsnprintf(s_szBuf, s_szBufSize, szFormat, argptr);
|
||||
|
||||
#if wxUSE_GUI
|
||||
wxMessageBox(s_szBuf, _("Fatal Error"), wxID_OK | wxICON_STOP);
|
||||
#else
|
||||
wxFprintf(stderr, _("Fatal error: %s\n"), s_szBuf);
|
||||
#endif
|
||||
wxSafeShowMessage(_T("Fatal Error"), s_szBuf);
|
||||
|
||||
abort();
|
||||
}
|
||||
|
Reference in New Issue
Block a user