Subroutines > Detailed Descriptions > AUI > Control > AUI_Control Parameters > opcode

Query Checkbox

CTLOP_QRYCB (opcode 5) is similar to opcode 0, except that it is only applicable to checkboxes and radio buttons, and only returns an indication of whether the button is checked or not by setting cstatus to 0 for unchecked, 1 for checked, or 2 for indeterminate. (The indeterminate state only applies to MBF_3STATE checkboxes.) As with other opcodes, a negative cstatus indicates an error.

The ability to query the value of a checkbox is useful when you want to present a bunch of checkboxes and let the user click on them in any order, without having to code all the INFLD exitcode logic necessary to support arbitrary cursor motion. For example, consider the following simple dialog (from the TSTEVW sample; see SOSLIB).

The dialog above could be created with code similar to the following:

MAP1 CID(7),B,2       ! control Ids for the checkboxes

MAP1 CB(7),B,1        ! chkbox state (0=unchecked, 1=checked)

MAP1 OPTDLGID,B,2     ! ID of dialog box

MAP1 STATUS,F,6

MAP1 NOSTATUS$,S,1,""  ! use when we do not care about status or ID

 

CREATE'DIALOG:

OPTDLGID = 0

xcall AUI,AUI_CONTROL, CTLOP_INFO, OPTDLGID, "Eventwait Option Flags", MBST_ENABLE, MBF_DIALOG + MBF_SYSMENU, "", "", STATUS, 2, 2, 11, 23

 

if OPTDLGID = 0 then goto ERROR'OUT

 

!(assume that CB(1-7) values have been initialized appropriately)

 

xcall AUI, AUI_CONTROL, CTLOP_INFO, CID(1), "Start on next control (1)", MBST_ENABLE, MBF_CHKBOX + MBF_LFJUST, "", CB(1), STATUS, 2, 3, 2, 21, -2, -2, 0, 0, "", "", OPTDLGID

xcall AUI, AUI_CONTROL, CTLOP_INFO, CID(2), "Do not wait for event (2)", MBST_ENABLE, MBF_CHKBOX + MBF_LFJUST, "", CB(2), STATUS, 3, 3, 3, 21, -2, -2, 0, 0, "", "", OPTDLGID

xcall AUI, AUI_CONTROL, CTLOP_INFO, CID(3), "Do not wrap (4)", MBST_ENABLE, MBF_CHKBOX + MBF_LFJUST, "", CB(3), STATUS, 4, 3, 4, 21, -2, -2, 0, 0, "", "", OPTDLGID

xcall AUI, AUI_CONTROL, CTLOP_INFO, CID(4), "Do not set focus (8)", MBST_ENABLE, MBF_CHKBOX + MBF_LFJUST, "", CB(4), STATUS, 5, 3, 5, 21, -2, -2, 0, 0, "", "", OPTDLGID

xcall AUI, AUI_CONTROL, CTLOP_INFO, CID(5), "Allow numeric input (16)", MBST_ENABLE, MBF_CHKBOX + MBF_LFJUST, "", CB(5), STATUS, 6, 3, 6, 21, -2, -2, 0, 0, "", "", OPTDLGID

xcall AUI, AUI_CONTROL, CTLOP_INFO, CID(6), "Descend into child groups (32)", MBST_ENABLE, MBF_CHKBOX + MBF_LFJUST, "", CB(6), STATUS, 7, 3, 7, 21, -2, -2, 0, 0, "", "", OPTDLGID

xcall AUI, AUI_CONTROL, CTLOP_INFO, CID(7), "Allow focus on siblings of parent control (64)", MBST_ENABLE, MBF_CHKBOX + MBF_LFJUST, "", CB(7), STATUS, 8, 3, 8, 21, -2, -2, 0, 0, "", "", OPTDLGID

xcall AUI, AUI_CONTROL, CTLOP_INFO, 0, "OK", MBST_ENABLE, MBF_BUTTON + MBF_KBD, "%VK_F2%", "", NOSTATUS$, 9, 4, 9, 10, -2, -2, 0, 0, "", "", OPTDLGID

xcall AUI, AUI_CONTROL, CTLOP_INFO, 0, "Cancel", MBST_ENABLE, MBF_BUTTON + MBF_KBD, "%VK_ESC%", "", NOSTATUS$, 9, 13, 9, 19, -2, -2, 0, 0, "", "", OPTDLGID

Having created the dialog, we can allow the user to click on the buttons without any further program intervention.

When the user clicks on the OK button (which we can detect by the fact that it was defined to act like the F2 key), we can query the values of the checkboxes with the following code:

For I = 1 to 7

xcall AUI, AUI_CONTROL, CTLOP_QRYCB, CID(I), "", 0, 0, "", "", STATUS

If STATUS >= 0 then

CB(I) = STATUS     ! 0=unchecked; 1=checked;

Else

? "Error querying checkbox"

Endif

Next I

 

Under A-Shell/Windows, the above operation to query the checkboxes would not actually be necessary, since it will set the CB(x) variables directly in real time as the checkboxes are checked. However, that feature is not supported when the application is running on a server other than the local workstation, so the query method is more universal.

See Also

Get Control ID for an example scenario involving the need to query a radio button in order to enable/disable another control.