Retrieve Date
To retrieve the selected date (either in response to receiving the click string or exitcode, or whenever you like), use opcode CTLOP_QRYCB (5) to query the control. This opcode was previously only used for querying a checkbox, but takes on a slightly different meaning here:
xcall AUI, AUI_CONTROL, CTLOP_QRYCB, id, ctext$, cstate, ctype, cmd$, "", cstatus
Set id to the id number of the control (as returned from the CTLOP_ADD) operation. The currently selected date will be returned in cstatus as a number with the following format: CCYYMMDD. (You can convert it to a string and parse it out into subfields as you like.) The ctext$, cstate, ctype, and cmd$ parameters are ignored.
Set Date
To set the date in the calendar, use the CTLOP_CHG opcode and put the date (in CCYYMMDD format) into the ctext$ parameter, as if you were changing the text of a control. Set the cstate parameter to MBST_TEXTONLY:
xcall AUI, AUI_CONTROL, CTLOP_CHG, id, ctext$, MBST_TEXTONLY
Set Limits
To limit the calendar to a range of dates, Use the CTLOP_CHG operation as for setting the date, except format the ctext$ parameter as a 17 byte string of two dates in CCYYMMDD format with a dash in between, for example:
CTEXT$ = "20050120-20070630" ! range of 15-Jan-05 thru 30-Jun-07
xcall AUI, AUI_CONTROL, CTLOP_CHG, ID, CTEXT$, MBST_TEXTONLY
Set Day States
As an added feature, you can force selected dates to be shown in bold. To do so, specify the MCS_DAYSTATES flag (in the winstyle parameter) when creating the control. You must then send a string of 0's and 1's to the control to update the day states for the current month when the control is first displayed and whenever the month changes (which will require you to respond to the click code). Set the ctext$ parameter to a string 31 digits long, representing the days 1-31 of the current month. (Set any extra days to 0). 0 indicates the normal state, and 1 the bold state. Then use the same CTLOP_CHG format as shown above for setting the date. The control will determine which attribute you are setting by the fact that the ctext$ string is exactly 31 bytes long. For example::
CTEXT$ = "1000000000000010000000000000000" ! bold 1st & 15th
xcall AUI, AUI_CONTROL, CTLOP_CHG, ID, CTEXT$, MBST_TEXTONLY
Note that this mechanism currently is only supported for one month at a time (so see the discussion above about specifying the coordinates to make sure that the control is not big enough to show multiple months).
The calendar control, when positioned on top of another control in the same window, allows the control underneath to "bleed" through (both visually and when processing mouse clicks). (This is just a Windows quirk of that control.) The normal way to avoid such problems with it is to not position on top of another control (seems reasonable), or, if you insist, then first enclose it in a separate dialog. However, if neither of those options is desirable, yet another possibility is to remove the child flag from the control, so that it acts like a top-level popup or overlapped window. To do so, add the WS_VISIBLE flag, and optionally, the WS_POPUP flags in the dwStyle parameter. (e.g. DWSTYLE = WS_CAPTION + WS_SYSMENU + WS_VISIBLE). This essentially turns the calendar control into its own dialog, which has its own downsides (affecting the positioning and also making it difficult to use in conjunction with another control to receive the date clicked on), but for cases where you just want to have a floating calendar handy, this may be an easier technique than manually creating your own modeless dialog to house the calendar control.
The reason why adding WS_VISIBLE removes the child flag (WS_CHILD) is that if neither WS_VISIBLE nor WS_CHILD are specified, both are turned on by default. Turning on the visible flag explicitly removes the default.