Interactive PowerBasic Forum

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Source Code => Graphics and Multimedia => GDI+ (GDI Plus) => Topic started by: José Roca on June 22, 2008, 02:35:17 PM

Title: GDI+: GdipCreateFontFamilyFromName
Post by: José Roca on June 22, 2008, 02:35:17 PM


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


(http://www.jose.it-berater.org/captures/GdipCreateFontFamilyFromName.png)