BCX_CHECKBOX function

Purpose:

BCX_CHECKBOX creates a checkbox, whose check state automatically toggles between checked and cleared each time the user selects the check box.

Syntax:

hCtl = BCX_CHECKBOX(Text AS STRING, _
                hwndParent AS HWND, _
                 hCtlID AS INTEGER, _
                   Xpos AS INTEGER, _
                   Ypos AS INTEGER, _
                  Width AS INTEGER, _
                 Height AS INTEGER  _
            [, WinStyle AS INTEGER] _
          [, ExWinStyle AS INTEGER])

Return Value:

  • Data type: HWND
    hCtl The handle of the checkbox, if the function succeeds. If the function fails, the return value is NULL.

Parameters:

  • Data type: STRING
    Text Label for the checkbox.
  • Data type: HWND
    hwndParent The handle of the parent window of the checkbox being created.
  • Data type: INTEGER
    hCtlID Specifies the identifier of the checkbox being created. The identifier is an integer value used by the checkbox being created to notify its parent about events. The identifier must be unique for each control created with the same parent window.
  • Data type: INTEGER
    Xpos Specifies the initial horizontal x-coordinate value of the upper-left corner location of the checkbox being created relative to the upper-left corner of the parent window's client area.
  • Data type: INTEGER
    Ypos Specifies the initial vertical y-coordinate value of the upper-left corner location of the checkbox being created relative to the upper-left corner of the parent window's client area.
  • Data type: INTEGER
    Width Specifies the width, in device units or, if the PIXELS optional parameter was specified in the GUI statement, in pixels, of the checkbox being created. If the width is equal to zero, the checkbox will be resized automatically to accommodate the width of the caption.
  • Data type: INTEGER
    Height Specifies the height, in device units or, if the PIXELS optional parameter was specified in the GUI statement, in pixels, of the checkbox being created.
  • Data type: INTEGER
    WinStyle [OPTIONAL] If the WinStyle parameter is used, the default Window Style for a BCX_CHECKBOX control, WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | WS_TABSTOP, is replaced with the value in WinStyle. For more information, visit the Microsoft Button Control Styles webpage and the Microsoft Window Styles webpage
  • Data type: INTEGER
    ExWinStyle [OPTIONAL] The default Extended Window Style for a BCX_CHECKBOX control is 0. For more information, visit the Microsoft Extended Window Styles webpage.

Example:

GUI "bcxChkBoxDemo", PIXELS ' Window class name 

MACRO IDC_Label = 100
MACRO IDC_CKB = 500
MACRO IDC_ProcessBtn = 600

MACRO wdDlg = 400
MACRO htDlg = 220
MACRO wdBtn = 150
MACRO htBtn = 30
MACRO sLabel1 = "The objective here is to test reading a BCX_CHECKBOX checked status "
MACRO sLabel2 = "and secondarily to test colorizing a BCX_CHECKBOX."
MACRO sLabel3 = "DIRECTIONS: CLICK ANY BCX_CHECKBOX, THEN CLICK THE BUTTON. "

GLOBAL hME AS HWND
GLOBAL hLabel[3] AS CONTROL
GLOBAL hCheckBox[10] AS CONTROL
GLOBAL hProcessBtn AS CONTROL

MACRO crNavy = 0x00800000 ' note: 0x00BBGGRR 
MACRO crGainsboro = 0x00DCDCDC ' anything other than (dull-and-boring) ms gray 
' --- end of declarations and constants ---------- 

SUB FORMLOAD
  LOCAL cbxTop AS INTEGER : cbxTop = 70
  LOCAL wdCBX AS INTEGER : wdCBX = wdDlg / 2
  GLOBAL m_nChkBox AS INTEGER : m_nChkBox = 2 ' zero-based 
  LOCAL spBtn AS INTEGER : spBtn = (wdDlg - 2 * wdBtn - 20) / 2
  ' ------------------------------------------------ 

  hME = BCX_FORM(" BCX_CHECKBOX Demo ", 0, 0, wdDlg, htDlg)
  BCX_SET_FORM_COLOR(hME, crGainsboro)

  hLabel[0] = BCX_LABEL(sLabel1, hME, IDC_Label, 10, 10, wdDlg - 20, 15)
  hLabel[1] = BCX_LABEL(sLabel2, hME, IDC_Label + 1, 10, 25, wdDlg - 20, 15)
  hLabel[2] = BCX_LABEL(sLabel3, hME, IDC_Label + 2, 10, 45, wdDlg - 20, 15)

  hCheckBox[0] = BCX_CHECKBOX(" This is BCX_CHECKBOX 1 ", hME, IDC_CKB + 1, 20, cbxTop, wdCBX, 15)
  cbxTop = cbxTop + 20
  hCheckBox[1] = BCX_CHECKBOX(" This is BCX_CHECKBOX 2 ", hME, IDC_CKB + 2, 20, cbxTop, wdCBX, 15)
  cbxTop = cbxTop + 20
  hCheckBox[2] = BCX_CHECKBOX(" This is BCX_CHECKBOX 3 ", hME, IDC_CKB + 3, 20, cbxTop, wdCBX, 15)
  cbxTop = cbxTop + 20

  hProcessBtn = BCX_BUTTON("Read BCX_CHECKBOX Selections", hME, IDC_ProcessBtn, spBtn, cbxTop + 20, 2 * wdBtn, htBtn)
  BCX_SET_FONT(hProcessBtn, "Verdana", 10, FW_SEMIBOLD )

  CENTER(hME)
  SHOW(hME)

END SUB ' formload 


BEGIN EVENTS
  LOCAL sResult AS STRING * 256 : sResult = ""
  LOCAL sCBXstatus AS STRING * 16

  SELECT CASE CBMSG

  CASE WM_COMMAND
    ' Test control id 
    IF (CBCTL = IDC_ProcessBtn) THEN
      ' Read the checkbox's checked status, and post the result. 
      ' Testing checked status 
      FOR INTEGER iCBX = 0 TO m_nChkBox
        IF (SendMessage(hCheckBox[iCBX], BM_GETCHECK, 0, 0) = BST_CHECKED) THEN
          sCBXstatus = "CHECKED"
        ELSE
          sCBXstatus = "NOT CHECKED"
        END IF
        ' Note that the results are one-based (iCBX + 1) 
        sResult = sResult & " BCX_CHECKBOX[" & STR$(iCBX + 1) & "] was " & sCBXstatus & CRLF
      NEXT ' iCBX 
      MSGBOX sResult, " BCX_CHECKBOX Test Results ", MB_ICONINFORMATION BOR MB_OK
    END IF
    EXIT FUNCTION

  CASE WM_CTLCOLORSTATIC
    ' Colorize the static label controls 
    ' Note:  The WM_CTLCOLORSTATIC wParam is the hDC, and the lParam is the window handle... 
    FOR INTEGER iLBL = 0 TO 2 ' colorize the static/label controls... 
      ' Test label handle. lParam needs to be typecast. 
      IF ((HANDLE) lParam = hLabel[iLBL]) THEN
        BCX_SET_LABEL_COLOR(hLabel[iLBL], crNavy, crGainsboro)
      END IF
    NEXT ' iLBL 

    ' Colorize the checkboxes... 
    ' Note: You cannot colorize your BCX_CHECKBOX controls in the main program, 
    '   it has to be done here.  And don't be put off because the message and 
    '   the bcx statement seem to be referring to a static label control. 
    '   WM_CTLCOLORSTATIC is used for any control that displays text 
    '   using the default control background color. 
    '   This includes check boxes, radio buttons, group boxes, static text, 
    '   read-only or disabled edit controls, and disabled combo boxes (all styles). 
    '   The changes affect the text drawn in the control. Changes do not affect 
    '   the checkmarks on the buttons or the outline of the group box. 
    FOR INTEGER iCBX = 0 TO m_nChkBox
      IF ((HANDLE) lParam = hCheckBox[iCBX]) THEN
        BCX_SET_LABEL_COLOR(hCheckBox[iCBX], crNavy, crGainsboro)
      END IF
    NEXT ' iCBX 
    EXIT FUNCTION

  CASE WM_CLOSE
    DestroyWindow(hME)
    EXIT FUNCTION

  END SELECT
END EVENTS

Remarks:

The default window Style for a BCX_CHECKBOX control also can be changed by using the MODSTYLE function.

For an example of the BCX_CHECKBOX function see Demo.bas.