BCX_PRINT function

Purpose:

The BCX_PRINT function writes a text string at the specified horizontal and vertical coordinates location. The currently selected font, text foreground, and text background color are used.

Syntax:

RetVal = BCX_PRINT(HndlWnd, _
           Xpos AS INTEGER, _
           Ypos AS INTEGER, _
            Text AS STRING _
                [, DrawHDC])

Return Value:

  • Data type: INTEGER
    RetVal is a nonzero integer if the function succeeds, zero if the function fails.

Parameters:

  • Data type: HWND
    HndlWnd The handle identifies the window where printing takes place.
    👉 The HndlWnd parameter must be set to 0 if printing to an HDC.
  • Data type: INTEGER
    Xpos X-coordinate (horizontal) of the position.
  • Data type: INTEGER
    Ypos Y-coordinate (vertical) of the position.
  • Data type: STRING
    Text string literal or variable to be printed.
  • DrawHDC [OPTIONAL] HDC (Handle to Device Context) pointing to an already open HDC. This is useful if a device context is to be written to many times. In this case the programmer is responsible for closing the open HDC at the appropriate time.
    👉 If printing to an HDC, the HndlWnd parameter, above, must be set to 0.

Example:

GUI "BCX_PRINT"

SUB FORMLOAD
  GLOBAL Form1 AS HWND

  Form1 = BCX_FORM("BCX_PRINT", 0, 0, 130, 25)
  BCX_SET_FORM_COLOR(Form1,RGB(255, 255, 255))
  CENTER(Form1)
  SHOW(Form1)
END SUB

BEGIN EVENTS
  SELECT CASE CBMSG
  CASE WM_PAINT
    BCX_PRINT(Form1, 50, 10, "Hello World from BCX!")
  END SELECT
END EVENTS

BCX_PRINTEX statement

Purpose:

The BCX_PRINTEX statement writes a text string at the specified horizontal and vertical coordinates location. The currently selected font, text foreground color, text background color, font face and font size arguments are required for proper functioning.

Syntax:

BCX_PRINTEX(HndlWnd AS HWND, _
               Xpos AS LONG, _
               Ypos AS LONG, _
             Text AS STRING, _
           FG_Color AS LONG, _
           BG_Color AS LONG, _
         FontFace AS STRING, _
           FontSize AS LONG  _
                 [, DrawHDC])

Parameters:

  • Data type: HWND
    HndlWnd [OPTIONAL] The handle identifies the window where printing takes place.
    👉 The HndlWnd parameter must be set to 0 if printing to an HDC.
  • Xpos LONG data type, X-coordinate(horizontal) of the position.
  • Ypos LONG data type, Y-coordinate(vertical) of the position.
  • Data type: STRING
    Text string literal or variable to be printed.
  • FG_Color LONG data type, text foreground color.
  • FG_Color LONG data type, text background color.
  • Data type: STRING
    FontFace font typeface name to be used to print the text.
  • FontSize LONG data type, size of the font to be used to print the text.
  • DrawHDC [OPTIONAL] HDC (Handle to Device Context) pointing to an already open HDC. This is useful if a device context is to be written to many times. In this case the programmer is responsible for closing the open HDC at the appropriate time.
    👉 If printing to an HDC, the HndlWnd parameter, above, must be set to 0.

Example:

Cardioid and Beyond by QB64 Forum User BPLUS February 17, 2019.
Converted to BCX by MrBcx on August 04, 2023. Public Domain
This BCX version uses double buffering to control flicker. Double buffering refers to a back buffer (a block of memory) and the front buffer (the display screen). The screen shows one buffer while writing to a back buffer.

$BCXVERSION "8.0.2"

GUI "Cardioid and Beyond", PIXELS

CONST xmax    = 700
CONST ymax    = 700
CONST npoints = 200

SUB FORMLOAD
  GLOBAL Form1 AS HWND
  Form1 = BCX_FORM("Cardiod",  0, 0, xmax + 10, ymax + 30)
  MODSTYLE(Form1, 0, WS_MAXIMIZEBOX | WS_MINIMIZEBOX, FALSE)
  CENTER Form1
  SHOW   Form1
  CALL Drawit
END SUB

BEGIN EVENTS
  SELECT CASE CBMSG
  CASE WM_QUIT, WM_CLOSE, WM_DESTROY
    END
  END SELECT
END EVENTS

SUB Drawit
  DIM AS DOUBLE Mult, DA, R
  DIM AS LONG xx1, xx2, yy1, yy2, cx, cy
  cx = xmax/2
  cy = ymax/2
  DA = 0.0314159
  R = cx - 10
  BCX_PENSIZE = 2
  FOR Mult = 0 TO 100 STEP 0.01
    DOEVENTS
    SLEEP(1)
    BCX_BUFFER_START(xmax, ymax)
    '========================================== 
    BCX_PRINTEX(0, 10, 10, "Multiple: " + USING$("###.##", Mult),  RGB(128, 162, 225), RGB(0, 0, 0), "Verdana", 26, BCX_BUFFER)
    IF Mult = INT(Mult) THEN CALL ResetPlasma
    BCX_CIRCLE(0, cx, cy, R, Kolor, 0, BCX_BUFFER)
    FOR INT i = 1 TO npoints
      DOEVENTS
      xx1 = cx + R * COS(i * DA)
      yy1 = cy + R * SIN(i * DA)
      xx2 = cx + R * COS(Mult * i * DA)
      yy2 = cy + R * SIN(Mult * i * DA)
      CALL ChangePlasma
      BCX_LINE(0, xx1, yy1, xx2, yy2, Kolor, BCX_BUFFER )
    NEXT
    BCX_BUFFER_STOP(Form1)
  NEXT
  MSGBOX "Press Okay to close the window", "Completed!"
  END
END SUB

SUB ChangePlasma
  GLOBAL AS ULONG Kolor
  GLOBAL AS ULONG cN
  GLOBAL AS DOUBLE pR, pG, pB
  cN = cN + 1
  Kolor = RGB(127 + 127 * SIN(pR * cN), 127 + 127 * SIN(pG * cN), 127 + 127 * SIN(pB * cN))
END SUB

SUB ResetPlasma
  pR = RND ^ 2
  pG = RND ^ 2
  pB = RND ^ 2
END SUB