BCX_SET_FONT function

Purpose:

The BCX_SET_FONT function (Syntax 1) will return the handle to a logical font if the function succeeds. The BCX_SET_FONT statement (Syntax 2) will set the font in a Control according to the value in the fontface and fontsize arguments.

Syntax 1: Function

hFont = BCX_SET_FONT(FontFace AS STRING, _
                    FontSize AS INTEGER  _
                   [, Weight AS INTEGER] _
                   [, Italic AS INTEGER] _
                [, Underline AS INTEGER] _
               [, StrikeThru AS INTEGER] _
             [, CharacterSet AS INTEGER] _
                 [, Rotation AS INTEGER])

Syntax 2: Statement

  BCX_SET_FONT(HndlWnd AS HWND, _
            FontFace AS STRING, _
           FontSize AS INTEGER  _
          [, Weight AS INTEGER] _
          [, Italic AS INTEGER] _
       [, Underline AS INTEGER] _
      [, StrikeThru AS INTEGER] _
    [, CharacterSet AS INTEGER] _
        [, Rotation AS INTEGER])

Return Value:

  • Data type: HFONT
    hFont The handle to a logical font if the function succeeds, the return value is NULL if the function fails. When the font is no longer needed, the hFont handle is used with the function DeleteObject(hFont) to delete the font.

Parameters:

  • Data type: HWND
    HndlWnd In Syntax 2: Statement, the handle of the control in which the font is to be changed.
  • Data type: STRING
    FontFace String containing name of fontface to be used.
  • Data type: INTEGER
    FontSize Integer containing fontsize to be used.
  • Data type: INTEGER
    Weight [OPTIONAL] specifies the weight of the font by using one of the following predefined values
    • FW_DONTCARE
    • FW_THIN
    • FW_EXTRALIGHT
    • FW_LIGHT
    • FW_NORMAL
    • FW_REGULAR
    • FW_MEDIUM
    • FW_SEMIBOLD
    • FW_BOLD
    • FW_EXTRABOLD
    • FW_HEAVY
  • Data type: INTEGER
    Italic [OPTIONAL] If TRUE, an italic font will be set.
  • Data type: INTEGER
    Underline [OPTIONAL] If TRUE, an underlined font will be set.
  • Data type: INTEGER
    StrikeThru [OPTIONAL] If TRUE, an strikethru font will be set.
  • Data type: INTEGER
    CharacterSet [OPTIONAL] specifies the font character set by using one of the following predefined values.
    • ANSI_CHARSET
    • BALTIC_CHARSET
    • CHINESEBIG5_CHARSET
    • DEFAULT_CHARSET
    • EASTEUROPE_CHARSET
    • GB2312_CHARSET
    • GREEK_CHARSET
    • HANGUL_CHARSET
    • MAC_CHARSET
    • OEM_CHARSET
    • RUSSIAN_CHARSET
    • SHIFTJIS_CHARSET
    • SYMBOL_CHARSET
    • TURKISH_CHARSET
    • VIETNAMESE_CHARSET
  • Data type: INTEGER
    Rotation [OPTIONAL] in tenths of a degree.

Example:

GUI "BCX_Font_Rotation"

SUB FORMLOAD
  DIM Form1   AS CONTROL
  DIM Label_1 AS CONTROL
  Form1 = BCX_FORM("BCX Font Rotation", 0, 0, 200, 200)
  Label_1 = BCX_LABEL("Hey Look, I'm Twisted!", Form1, 80, 55, 5, 215, 250, WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE)
  BCX_SET_FONT(Label_1, "Tahoma", 14, FW_BOLD, 1, 0, 0, 0, 450) ' the 450 = 450 TENTHS of a degree = 45 degrees 
  CENTER Form1
  SHOW Form1
END SUB

BEGIN EVENTS
END EVENTS

BCXFONT handle

The BCXFONT handle can be used to change the application's default font. Any BCX controls created, will use the font that is assigned to BCXFONT at that time. Setting BCXFONT to zero will use GetStockObject(DEFAULT_GUI_FONT) which is the default.

Example:

GUI "ButtonTest",PIXELS

GLOBAL form1 AS HWND
GLOBAL fnts[20] AS HFONT

SET fontname[] AS PCHAR
"Courier New","Comic Sans MS","Lucida Sans","Verdana"
END SET

SUB FORMLOAD
DIM RAW i,ii
form1 = BCX_FORM("Button AutoSize Test",0,0,840,550)

FOR i = 0 TO 3
  FOR ii = 0 TO 4
    fnts[i*ii] = BCX_SET_FONT(fontname$[i],8+(2*ii))
    BCXFONT = fnts[i*ii]
    BCX_BUTTON(fontname$[i] + STR$(8+(2*ii)),form1,0,10+i*220,10+ii*100)
  NEXT
NEXT

BCX_ButtonOld("This button uses the default font and the old sizing method",form1,0,10,10+5*90)
BCXFONT = 0
BCX_BUTTON("This button uses the default font and the new sizing method",form1,0,10,40+5*90)

CENTER(form1)
SHOW(form1)
END SUB

BEGIN EVENTS
SELECT CASE CBMSG
  CASE WM_CLOSE
  FOR integer i = 0 TO 19
    DeleteObject(fnts[i])
  NEXT i
END SELECT
END EVENTS

FUNCTION BCX_ButtonOld OPTIONAL(Text AS STRING, _
                                  hWnd AS HWND, _
                                            id, _
                                             X, _
                                             Y, _
                                           W=0, _
                                           H=0, _
                                       Style=0, _
                                    Exstyle=-1) AS HWND
$CCODE

 if(!Style)
 {
  Style=WS_CHILD | WS_VISIBLE | BS_MULTILINE | BS_PUSHBUTTON | WS_TABSTOP;
 }
  if(Exstyle==-1)
   {
    Exstyle=WS_EX_STATICEDGE;
   }
 HWND A = CreateWindowEx(Exstyle,"button",Text,Style,
          X*BCX_SCALEX, Y*BCX_SCALEY, W*BCX_SCALEX, H*BCX_SCALEY,
          hWnd,(HMENU)id,BCX_HINSTANCE,NULL);
 SendMessage(A,(UINT)WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),(LPARAM)MAKELPARAM(FALSE,0));
 if(W==0)
 {
  HDC hdc=GetDC(A);
  SIZE sz;
  GetTextExtentPoint32(hdc,Text,strlen(Text),&sz);
  ReleaseDC(A,hdc);
  MoveWindow(A,X*BCX_SCALEX,Y*BCX_SCALEY,sz.cx+(sz.cx*0.5),sz.cy+(sz.cy*0.32),TRUE);
 }

 $CCODE

FUNCTION = A
END FUNCTION

BCX GUI Sample Programs using the BCX_SET_FONT statement