From 35f35ea407d602f73c5fbe38a4bf6cc243ac3368 Mon Sep 17 00:00:00 2001 From: Rebel_X Date: Sat, 13 Feb 2016 12:55:17 +0100 Subject: [PATCH] Clean up wxMSW tooltip window on library shutdown Not doing this prevented the tooltips from working correctly if the library was shut down and reinitialized again, so add a module ensuring this is done. Closes #17360. --- include/wx/msw/tooltip.h | 6 ++++++ src/msw/tooltip.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/wx/msw/tooltip.h b/include/wx/msw/tooltip.h index caf4b753c8..4c3be08cec 100644 --- a/include/wx/msw/tooltip.h +++ b/include/wx/msw/tooltip.h @@ -74,6 +74,9 @@ public: static void UpdateVisibility(); private: + // This module calls our DeleteToolTipCtrl(). + friend class wxToolTipModule; + // Adds a window other than our main m_window to this tooltip. void DoAddHWND(WXHWND hWnd); @@ -92,6 +95,9 @@ private: // create the tooltip ctrl if it doesn't exist yet and return its HWND static WXHWND GetToolTipCtrl(); + // to be used in wxModule for deleting tooltip ctrl window when exiting mainloop + static void DeleteToolTipCtrl(); + // new tooltip maximum width, defaults to min(display width, 400) static int ms_maxWidth; diff --git a/src/msw/tooltip.cpp b/src/msw/tooltip.cpp index cff40f66fd..6173ede3e6 100644 --- a/src/msw/tooltip.cpp +++ b/src/msw/tooltip.cpp @@ -134,6 +134,30 @@ public: } }; +// Takes care of deleting ToolTip control window when shutting down the library. +class wxToolTipModule : public wxModule +{ +public: + wxToolTipModule() + { + } + + virtual bool OnInit() wxOVERRIDE + { + return true; + } + + virtual void OnExit() wxOVERRIDE + { + wxToolTip::DeleteToolTipCtrl(); + } + +private: + wxDECLARE_DYNAMIC_CLASS(wxToolTipModule); +}; + +wxIMPLEMENT_DYNAMIC_CLASS(wxToolTipModule, wxModule); + #ifdef __VISUALC__ #pragma warning( default : 4097 ) #endif @@ -253,6 +277,15 @@ void wxToolTip::SetMaxWidth(int width) ms_maxWidth = width; } +void wxToolTip::DeleteToolTipCtrl() +{ + if ( ms_hwndTT ) + { + ::DestroyWindow((HWND)ms_hwndTT); + ms_hwndTT = (WXHWND)NULL; + } +} + // --------------------------------------------------------------------------- // implementation helpers // ---------------------------------------------------------------------------