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:
Parameters:
|
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
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.