[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re[2]: [lmi] Displaying messages during wx startup
From: |
Vadim Zeitlin |
Subject: |
Re[2]: [lmi] Displaying messages during wx startup |
Date: |
Sat, 18 Jul 2009 14:02:48 +0200 |
On Wed, 01 Apr 2009 14:53:47 +0000 Greg Chicares <address@hidden> wrote:
GC> On 2009-03-27 23:56Z, Vadim Zeitlin wrote:
GC> > On Fri, 27 Mar 2009 12:15:18 +0000 Greg Chicares <address@hidden> wrote:
GC> >
GC> > GC> Consider the patch below, which attempts to display a warning message
GC> > GC> on the first line of the main function. Is there some way to make the
GC> > GC> wxLogWarning message get displayed, even before wx has been
initialized?
GC> > GC> I suspect the answer is "no",
GC> >
GC> > I'm afraid currently it is although to be honest I don't have any
GC> > reasonable explanation as to why is it so -- wx surely could use
GC> > MessageBox() under Windows internally to ensure that the log messages are
GC> > always shown. I think it would be worthwhile to change wxLog to use
GC> > wxMessageOutputMessageBox instead of wxLogStderr by default in GUI MSW
GC> > programs, what do you think?
GC>
GC> I agree.
I've finally done this in http://trac.wxwidgets.org/changeset/60875. I
used this patch to the minimal sample to test it
Index: samples/minimal/minimal.cpp
===================================================================
--- samples/minimal/minimal.cpp (revision 61431)
+++ samples/minimal/minimal.cpp (working copy)
@@ -30,6 +30,12 @@
#include "wx/wx.h"
#endif
+static struct L
+{
+ L() { wxLogMessage("In L ctor"); }
+ ~L() { wxLogMessage("In L dtor"); }
+} theL;
+
// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------
@@ -48,6 +54,9 @@
class MyApp : public wxApp
{
public:
+ MyApp() { wxLogMessage("In MyApp ctor"); }
+ ~MyApp() { wxLogMessage("In MyApp dtor"); }
+
// override base class virtuals
// ----------------------------
@@ -106,8 +115,17 @@
// static object for many reasons) and also implements the accessor function
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
// not wxApp)
-IMPLEMENT_APP(MyApp)
+IMPLEMENT_APP_NO_MAIN(MyApp)
+extern "C" int WINAPI
+WinMain(HINSTANCE hInstance, HINSTANCE, wxCmdLineArgType, int nCmdShow)
+{
+ wxLogMessage("In the beginning was WinMain().");
+ int rc = wxEntry(hInstance, 0, NULL, nCmdShow);
+ wxLogMessage("Bye");
+ return rc;
+}
+
// ============================================================================
// implementation
// ============================================================================
And after my changes all messages are shown in message boxes to the user as
expected. The only drawback is that the final log target (used for showing
the messages logged after wxEntry() return) is leaked but it seems better
to leak memory (which shouldn't matter much when the application is going
to terminate anyhow) than to not show (possibly important) messages.
IOW wxLogXXX() functions should now be safe to use at any time.
Regards,
VZ
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re[2]: [lmi] Displaying messages during wx startup,
Vadim Zeitlin <=