BCX_FONTDLG function

Purpose:

BCX_FONTDLG function creates a font dialog box in which font attributes can be chosen. These attributes include a typeface name, style (bold, italic, or regular), point size, effects (underline, strikeout, and text color), and a script (or character set).

Syntax:

RetVal = BCX_FONTDLG([UseLast AS BOOL][, HndlWnd AS HWND])

Return Value:

  • Data type: INTEGER
    RetVal Nonzero if the user clicks the OK button of the dialog box. The BCX_FONT structure members indicate the user's selections.

    The return value is zero if the user cancels or closes the Font dialog box or if an error occurs. Call the CommDlgExtendedError function to get EXTENDED ERROR information. CommDlgExtendedError can return one of the following values:

    • CDERR_FINDRESFAILURE CDERR_NOHINSTANCE
    • CDERR_INITIALIZATION CDERR_NOHOOK
    • CDERR_LOCKRESFAILURE CDERR_NOTEMPLATE
    • CDERR_LOADRESFAILURE CDERR_STRUCTSIZE
    • CDERR_LOADSTRFAILURE CFERR_MAXLESSTHANMIN
    • CDERR_MEMALLOCFAILURE CFERR_NOFONTS

Parameters:

  • Data type: BOOL
    UseLast [OPTIONAL] TRUE or FALSE, the default argument of this parameter is set to FALSE. If the argument is set as TRUE, the dialog values will default to those which were selected the last time the BCX_FONTDLG function was called. These values also can be changed by setting the elements of the BCX declared variable BCX_FONT. See below for BCX_FONT details.
  • Data type: HWND
    HndlWnd [OPTIONAL] If a window handle is specified, the dialog will be set as MODAL.

BCX_FONTDLG also creates a BCX_FONT structure populated with the following members with values derived from the choices made in the font dialog box.

See below for an example of how to retrieve these values.

Example 1:

DIM RetVal%

RetVal% = BCX_FONTDLG      ' Fill the BCX_FONT structure
PRINT "BCX_FONT.Name$     = ", BCX_FONT.Name$     ' Font Name
PRINT "BCX_FONT.Size      =" , BCX_FONT.Size      ' Font Point Size
PRINT "BCX_FONT.Italic    =" , BCX_FONT.Italic    ' Boolean(0 or 1)
PRINT "BCX_FONT.Bold      =" , BCX_FONT.Bold      ' Boolean(0 or 1)
PRINT "BCX_FONT.Underline =" , BCX_FONT.Underline ' Boolean(0 or 1)
PRINT "BCX_FONT.Strikeout =" , BCX_FONT.Strikeout ' Boolean(0 or 1)
PRINT "BCX_FONT.Rgb       =" , BCX_FONT.Rgb       ' RGB font color

Example 2:

GUI "MiniEd"

SUB FORMLOAD
  GLOBAL Form1            AS CONTROL
  GLOBAL Edit1            AS CONTROL
  GLOBAL Button1          AS CONTROL

  '******************************************************************** 
  Form1   = BCX_FORM ( "Mini-Editor",              0,  0, 125, 105)
  Edit1   = BCX_EDIT ( " BCX rocks!", Form1, 101,  5, 20, 105, 60)
  Button1 = BCX_BUTTON( "Change Font", Form1, 102, 35,  3,  40, 13)
  '******************************************************************** 
  CENTER(Form1)       ' Center our Form on the screen 
  SHOW (Form1)       ' Display our creation! 
END SUB

BEGIN EVENTS
  SELECT CASE CBMSG
    '******************************************************************** 
  CASE WM_COMMAND
    '******************************************************************** 
    IF CBCTL = 102 THEN
      CALL SetCustomFont()
    END IF

    '******************************************************************** 
  CASE WM_CTLCOLOREDIT
    '******************************************************************** 
    IF (HANDLE)lParam = Edit1 THEN
      BCX_SET_EDIT_COLOR(Edit1, BCX_Font.RGB, QBCOLOR(31))
    END IF

    '******************************************************************** 
  CASE WM_CLOSE
    '******************************************************************** 
    LOCAL id
    id = MSGBOX("Are you sure?", _
                "Quit Program!", _
    MB_YESNO OR MB_ICONQUESTION)
    IF id = IDYES THEN DestroyWindow(hWnd)
    EXIT FUNCTION
  END SELECT
END EVENTS

SUB SetCustomFont ()
  DIM RetVal

  RetVal = BCX_FONTDLG      ' Fill the BCX_FONT structure 
 IF RetVal THEN
   BCX_SET_FONT(Edit1, BCX_Font.Name$, _
                        BCX_Font.Size, _
                        BCX_Font.Bold, _
                      BCX_Font.Italic, _
                   BCX_Font.Underline, _
                   BCX_Font.Strikeout)
 END IF
END SUB