diff --git a/include/wx/msw/notebook.h b/include/wx/msw/notebook.h index 1d4b4b571d..2d61b428f1 100644 --- a/include/wx/msw/notebook.h +++ b/include/wx/msw/notebook.h @@ -202,6 +202,9 @@ private: // It has the same semantics as HitTest(). int MSWHitTestLeftRight(const wxPoint& pt, long *flags) const; + // Subclass the spin button if it exists. + void MSWSubclassSpin(); + wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxNotebook); wxDECLARE_EVENT_TABLE(); }; diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index eb758ed04b..57f5887fea 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -980,6 +980,24 @@ wxNotebookSpinBtnWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) hwnd, message, wParam, lParam); } +void wxNotebook::MSWSubclassSpin() +{ + if ( !m_hasSubclassedUpdown ) + { + // Find the spin button. + HWND hwndSpin = FindWindowExA(m_hWnd, nullptr, UPDOWN_CLASSA, nullptr); + if ( hwndSpin ) + { + // Subclass the spin button. + if ( !gs_wndprocNotebookSpinBtn ) + gs_wndprocNotebookSpinBtn = wxGetWindowProc(hwndSpin); + + wxSetWindowProc(hwndSpin, wxNotebookSpinBtnWndProc); + m_hasSubclassedUpdown = true; + } + } +} + LRESULT APIENTRY wxNotebookWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -1528,31 +1546,7 @@ void wxNotebook::OnSize(wxSizeEvent& event) false); } - // subclass the spin control used by the notebook to scroll pages to - // prevent it from flickering on resize - if ( !m_hasSubclassedUpdown ) - { - // iterate over all child windows to find spin button - for ( HWND child = ::GetWindow(GetHwnd(), GW_CHILD); - child; - child = ::GetWindow(child, GW_HWNDNEXT) ) - { - wxWindow *childWindow = wxFindWinFromHandle((WXHWND)child); - - // see if it exists, if no wxWindow found then assume it's the spin - // btn - if ( !childWindow ) - { - // subclass the spin button to override WM_ERASEBKGND - if ( !gs_wndprocNotebookSpinBtn ) - gs_wndprocNotebookSpinBtn = wxGetWindowProc(child); - - wxSetWindowProc(child, wxNotebookSpinBtnWndProc); - m_hasSubclassedUpdown = true; - break; - } - } - } + MSWSubclassSpin(); event.Skip(); }