• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

GDI: EnumFontFamiliesEx Function

Started by José Roca, August 22, 2011, 01:50:32 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
The following code enumerates all styles and charsets of the Times New Roman font.


' ########################################################################################
' The following code enumerates all styles and charsets of the Times New Roman font.
' ########################################################################################

' CSED_PBCC - Use the PBCC compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL hdc AS DWORD
   LOCAL lf AS LOGFONT

   ' Create a device context
   hdc = GetDC(%HWND_DESKTOP)
   lf.lfFaceName = "Times New Roman"
   lf.lfCharset = %DEFAULT_CHARSET
   ' Enumerate the fonts
   EnumFontFamiliesEx hDc, lf, CODEPTR(EnumFontFamExProc), %NULL, 0
   ' Delete the device context
   DeleteDC hdc

   WAITKEY$

END FUNCTION
' ========================================================================================

' ========================================================================================
' EnumFontFamExProc callback procedure
' ========================================================================================
FUNCTION EnumFontFamExProc (BYREF lpelf AS ENUMLOGFONT, BYREF lpntm AS NEWTEXTMETRIC, BYVAL FontType AS DWORD, BYVAL lParam AS DWORD) AS LONG

   PRINT "Font name: " lpelf.elfFullName " ";
   PRINT "Font style: " lpelf.elfStyle " ";
   PRINT "Charset: " lpelf.elfLogFont.lfCharset " ";
   PRINT "Weight: " lpelf.elfLogFont.lfWeight
   FUNCTION = %TRUE

END FUNCTION
' ========================================================================================


José Roca

 
Same as above, but returning the output in a string.


' ########################################################################################
' The following code enumerates all styles and charsets of the Times New Roman font.
' ########################################################################################

' CSED_PBCC - Use the PBCC compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL hdc AS DWORD
   LOCAL lf AS LOGFONT
   LOCAL strOutput AS STRING

   ' Create a device context
   hdc = GetDC(%HWND_DESKTOP)
   lf.lfFaceName = "Times New Roman"
   lf.lfCharset = %DEFAULT_CHARSET
   ' Enumerate the fonts
   EnumFontFamiliesEx hDc, lf, CODEPTR(EnumFontFamExProc), VARPTR(strOutput), 0
   STDOUT strOutput
   ' Delete the device context
   DeleteDC hdc

   WAITKEY$

END FUNCTION
' ========================================================================================

' ========================================================================================
' EnumFontFamExProc callback procedure
' ========================================================================================
FUNCTION EnumFontFamExProc (BYREF lpelf AS ENUMLOGFONT, BYREF lpntm AS NEWTEXTMETRIC, BYVAL FontType AS DWORD, BYVAL lParam AS STRING PTR) AS LONG

   @lParam = @lParam & "Font name: " & lpelf.elfFullName & _
             " Font style: " & lpelf.elfStyle & _
             " Charset: " & FORMAT$(lpelf.elfLogFont.lfCharset) & _
             " Weight: " & FORMAT$(lpelf.elfLogFont.lfWeight) & $CRLF
   FUNCTION = %TRUE

END FUNCTION
' ========================================================================================