Re: CreateFontIndirect: will this cause a memory leak?

Tech-Archive recommends: Speed Up your PC by fixing your registry



Many thanks, Thorsten. That's cleared things up for me.

(Don't worry about the VidDC thing -- it was a copy and paste typo)

"Thorsten Albers" wrote:

Mark Raishbrook <MarkRaishbrook@xxxxxxxxxxxxxxxxxxxxxxxxx> schrieb im
Beitrag <39504D1F-041E-4776-B333-41D51F05DFAC@xxxxxxxxxxxxx>...
Dim hFont As Long, oldFont As Long
hFont = CreateFontIndirect(lF)
oldFont = SelectObject(DC, hFont)

Call TextOut(DC, iXPos, iYPos, sz, Len(sz))

lF.lfQuality = CLEARTYPE_QUALITY

hFont = CreateFontIndirect(lF)
oldFont = SelectObject(VidDC, hFont)

Call TextOut(DC, iXPos + iOffsetX, iYPos + iOffsetY, sz, Len(sz))

Call SelectObject(DC, oldFont)
Call DeleteObject(hFont)


hFont = CreateFontIndirect(lF)
If hFont Then

oldFont = SelectObject(DC, hFont)

Call TextOut(DC, iXPos, iYPos, sz, Len(sz))

lF.lfQuality = CLEARTYPE_QUALITY
hFontNew = CreateFontIndirect(lF)
If HFontNew Then
if SelectObject(VidDC, hFontNew) Then
' Should be 'DC' and not 'VidDC'???

Call DeleteObject(hFont)
hFont = hFontNew
hFontNew = 0

Call TextOut(DC, iXPos + iOffsetX, iYPos + iOffsetY, sz, Len(sz))

End If
End If

Call SelectObject(DC, oldFont)
If hFontNew Then DeleteObject(hFontNew)
Call DeleteObject(hFont)
End If

- CreateFontIndirect() doesn't know that previous a font has already been
created from the LOGFONT data; therefore you have to delete any font
created with CreateFontIndirect() explicitely
- A font can be deleted only after it has been deselected from any DC to
which it has been selected before

--
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
----------------------------------------------------------------------


.



Relevant Pages

  • Cleartype with doublebuffer
    ... I have noticed following registry key get created when Cleartype font ... HFONT hSysFont = GetStockObject; ... HFONT oldFont = NULL; ... hFontNew = CreateFontIndirect; ...
    (microsoft.public.pocketpc.developer)
  • Re: CreateFontIndirect: will this cause a memory leak?
    ... hFont = CreateFontIndirect ... oldFont = SelectObject ... Call TextOut(DC, iXPos + iOffsetX, iYPos + iOffsetY, sz, Len(sz)) ...
    (microsoft.public.vb.winapi.graphics)