Fix using invalid HFONT in wxGetTextMetrics()
If the window has no valid font, GetFont() returns a temporary font. Extend this font lifetime, so the HFONT remains valid till the end of the function.
This commit is contained in:
committed by
Vadim Zeitlin
parent
63c118f186
commit
c7efab6d8a
@@ -7421,7 +7421,12 @@ static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win)
|
|||||||
|
|
||||||
#if !wxDIALOG_UNIT_COMPATIBILITY
|
#if !wxDIALOG_UNIT_COMPATIBILITY
|
||||||
// and select the current font into it
|
// and select the current font into it
|
||||||
HFONT hfont = GetHfontOf(win->GetFont());
|
|
||||||
|
// Note that it's important to extend the lifetime of the possibly
|
||||||
|
// temporary wxFont returned by GetFont() to ensure that its HFONT remains
|
||||||
|
// valid.
|
||||||
|
const wxFont& f(win->GetFont());
|
||||||
|
HFONT hfont = GetHfontOf(f);
|
||||||
if ( hfont )
|
if ( hfont )
|
||||||
{
|
{
|
||||||
hfont = (HFONT)::SelectObject(hdc, hfont);
|
hfont = (HFONT)::SelectObject(hdc, hfont);
|
||||||
|
Reference in New Issue
Block a user