diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index e04c44db50..457ecb757d 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -965,6 +965,12 @@ WXDLLIMPEXP_CORE void wxFillLogFont(LOGFONT *logFont, const wxFont *font); WXDLLIMPEXP_CORE wxFont wxCreateFontFromLogFont(const LOGFONT *logFont); WXDLLIMPEXP_CORE wxFontEncoding wxGetFontEncFromCharSet(int charset); +inline void wxSetWindowFont(HWND hwnd, const wxFont& font) +{ + ::SendMessage(hwnd, WM_SETFONT, + (WPARAM)GetHfontOf(font), MAKELPARAM(TRUE, 0)); +} + WXDLLIMPEXP_CORE void wxSliderEvent(WXHWND control, WXWORD wParam, WXWORD pos); WXDLLIMPEXP_CORE void wxScrollBarEvent(WXHWND hbar, WXWORD wParam, WXWORD pos); diff --git a/include/wx/msw/subwin.h b/include/wx/msw/subwin.h index a0178147e7..038bf303f0 100644 --- a/include/wx/msw/subwin.h +++ b/include/wx/msw/subwin.h @@ -113,14 +113,11 @@ public: // set font for all windows void SetFont(const wxFont& font) { - HFONT hfont = GetHfontOf(font); - wxCHECK_RET( hfont, wxT("invalid font") ); - for ( size_t n = 0; n < m_count; n++ ) { if ( m_hwnds[n] ) { - ::SendMessage(m_hwnds[n], WM_SETFONT, (WPARAM)hfont, 0); + wxSetWindowFont(m_hwnds[n], font); // otherwise the window might not be redrawn correctly ::InvalidateRect(m_hwnds[n], NULL, FALSE /* don't erase bg */); diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index fc27322efc..af08c83b2d 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -620,8 +620,7 @@ bool wxListCtrl::SetHeaderAttr(const wxItemAttr& attr) // We need to tell the header about its new font to let it compute // its new height. - ::SendMessage(hwndHdr, WM_SETFONT, - (WPARAM)GetHfontOf(font), MAKELPARAM(TRUE, 0)); + wxSetWindowFont(hwndHdr, font); } // Refreshing the listview makes it notice the change in height of its diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index b7bd070f5e..b353eec254 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -552,7 +552,8 @@ int wxRendererMSW::GetHeaderButtonHeight(wxWindow * win) font = win->GetFont(); if ( !font.IsOk() ) wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); - ::SendMessage(hwndHeader, WM_SETFONT, (WPARAM)GetHfontOf(font), 0); + + wxSetWindowFont(hwndHeader, font); // initialize the struct filled with the values by Header_Layout() RECT parentRect = { 0, 0, 100, 100 }; diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 222c787bc9..6c794fb47a 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -564,8 +564,7 @@ bool wxSpinCtrl::SetFont(const wxFont& font) return false; } - WXHANDLE hFont = GetFont().GetResourceHandle(); - (void)::SendMessage(GetBuddyHwnd(), WM_SETFONT, (WPARAM)hFont, TRUE); + wxSetWindowFont(GetBuddyHwnd(), GetFont()); return true; } diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 0a380c0e8b..5f8ef7791d 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -827,11 +827,7 @@ bool wxWindowMSW::SetFont(const wxFont& font) // just been reset and in this case we need to change the font used by // the native window to the default for this class, i.e. exactly what // GetFont() returns - WXHANDLE hFont = GetFont().GetResourceHandle(); - - wxASSERT_MSG( hFont, wxT("should have valid font") ); - - ::SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); + wxSetWindowFont(hWnd, GetFont()); } return true;