diff --git a/include/wx/msw/apptbase.h b/include/wx/msw/apptbase.h index 2442bf3b61..c6d6ce4b45 100644 --- a/include/wx/msw/apptbase.h +++ b/include/wx/msw/apptbase.h @@ -58,6 +58,9 @@ public: // write text to the console, return true if ok or false on error virtual bool WriteToStderr(const wxString& text) = 0; + // return the main application window or 0 if none + virtual WXHWND GetMainHWND() const = 0; + protected: #if wxUSE_THREADS // implementation of WaitForThread() for the console applications which is diff --git a/include/wx/msw/apptrait.h b/include/wx/msw/apptrait.h index 4d6c29abc4..30a61d4f31 100644 --- a/include/wx/msw/apptrait.h +++ b/include/wx/msw/apptrait.h @@ -30,6 +30,7 @@ public: #endif // wxUSE_THREADS virtual bool CanUseStderr() wxOVERRIDE { return true; } virtual bool WriteToStderr(const wxString& text) wxOVERRIDE; + virtual WXHWND GetMainHWND() const wxOVERRIDE { return NULL; } }; #if wxUSE_GUI @@ -55,6 +56,7 @@ public: virtual bool CanUseStderr() wxOVERRIDE; virtual bool WriteToStderr(const wxString& text) wxOVERRIDE; + virtual WXHWND GetMainHWND() const wxOVERRIDE; }; #elif defined(__WXGTK__) @@ -85,6 +87,7 @@ public: virtual bool CanUseStderr() { return false; } virtual bool WriteToStderr(const wxString& WXUNUSED(text)) { return false; } + virtual WXHWND GetMainHWND() const wxOVERRIDE { return NULL; } }; #elif defined(__WXQT__) @@ -110,6 +113,7 @@ public: virtual bool CanUseStderr() { return false; } virtual bool WriteToStderr(const wxString&) { return false; } + virtual WXHWND GetMainHWND() const wxOVERRIDE { return NULL; } }; #endif diff --git a/src/common/log.cpp b/src/common/log.cpp index 3bf1c33d40..8122b7d9e2 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -183,7 +183,9 @@ private: void wxSafeShowMessage(const wxString& title, const wxString& text) { #ifdef __WINDOWS__ - ::MessageBox(NULL, text.t_str(), title.t_str(), MB_OK | MB_ICONSTOP); + const wxAppTraits* const traits = wxApp::GetTraitsIfExists(); + ::MessageBox(traits ? traits->GetMainHWND() : NULL, + text.t_str(), title.t_str(), MB_OK | MB_ICONSTOP); #else wxFprintf(stderr, wxS("%s: %s\n"), title.c_str(), text.c_str()); fflush(stderr); diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 17adabf9a8..d8b19f0295 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -603,6 +603,12 @@ bool wxGUIAppTraits::WriteToStderr(const wxString& WXUNUSED(text)) #endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS +WXHWND wxGUIAppTraits::GetMainHWND() const +{ + const wxWindow* const w = wxApp::GetMainTopWindow(); + return w ? w->GetHWND() : NULL; +} + // =========================================================================== // wxApp implementation // ===========================================================================