• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipCreateFontFamilyFromName

Started by José Roca, June 22, 2008, 02:35:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a Font object from a family name and uses it to draw text.


SUB GDIP_DrawString (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pFontFamily AS DWORD
   LOCAL pFont AS DWORD
   LOCAL pSolidBrush AS DWORD
   LOCAL strFontName AS STRING
   LOCAL strText AS STRING
   LOCAL rcf AS RECTF

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create the font
   strFontName = UCODE$("Arial")
   hStatus = GdipCreateFontFamilyFromName(STRPTR(strFontName), %NULL, pFontFamily)
   IF hStatus = %StatusOk AND pFontFamily <> %NULL THEN
      hStatus = GdipCreateFont(pFontFamily, 24, %FontStyleRegular, %UnitPoint, pFont)
      GdipDeleteFontFamily(pFontFamily)
   END IF

   ' Note: You can use the wrapper function GdiPlusCreateFontFromName to create the font:
'   hStatus = GdiPlusCreateFontFromName("Arial", 24, %FontStyleRegular, %UnitPoint, pFont)

   ' // Create a solid brush
   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 0, 0, 0), pSolidBrush)

   ' // Draw a string
   rcf.x = 30.0! : rcf.y = 30.0!
   strText = UCODE$("Drawing a string")
   hStatus = GdipDrawString(pGraphics, STRPTR(strText), LEN(strText) \ 2, pFont, rcf, %NULL, pSolidBrush)

   ' // Cleanup
   IF pFont THEN GdipDeleteFont(pFont)
   IF pSolidBrush THEN GdipDeleteBrush(pSolidBrush)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB