BCX_SET_FONT procedures

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$, _
                       FontSize%  _
                        [, Weight%] _
                      [, Italic%] _
                   [, Underline%] _
                  [, StrikeThru%] _
                [, CharacterSet%])

Syntax 2: Statement


 BCX_SET_FONT(hWnd, _
          FontFace$, _
          FontSize%  _
         [, Weight%] _
         [, Italic%] _
      [, Underline%] _
     [, StrikeThru%] _
   [, CharacterSet%])     

 Parameters:

  • hFont In the function(syntax 1), the handle to a logical font returned 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 to delete the font, that is, DeleteObject(hFont).
  • hWnd In the statement(syntax 2), the handle to the control in which the font is to be changed.
  • FontFace$ String containing name of fontface to be used.
  • FontSize% Integer containing fontsize to be used.
  • 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
  • Italic% [OPTIONAL] If TRUE, an italic font will be set.
  • Underline% [OPTIONAL] If TRUE, an underlined font will be set.
  • StrikeThru% [OPTIONAL] If TRUE, an strikethru font will be set.
  • 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

BCXFONT Global HFONT handle

The Global HFONT handle BCXFONT 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: BCXFONT and BCX_SET_FONT


 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$, _
                           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

For other examples of the BCX_SET_FONT statement see FontDemo.bas and FontDialogDemo.bas .