# Operations
> [HTML Version](operationsmoncalctrl.htm)
**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\$ = "20230120-20250630" \! range of 20-Jan-23 thru 30-Jun-25
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; see the discussion above about specifying the coordinates to make sure that the control is not big enough to show multiple months.
**Set Color Attributes**
There are two standard style/color variations of the calendar control, depending on whether the _ctype2_ MBF2\_NOTHEME bit is set when the control is created:
| | |
|------|------|
| **(./images/moncal11.jpg)**
| **(./images/moncal22.jpg)** |
| Standard themed version (Win11) | Standard non-themed version |
To change the color scheme for the non-themed version, use the following:
xcall AUI, AUI\_CONTROL, CTLOP\_CHG, ctlid, ctext\$, MBST\_TEXTONLY
where _ctext\$_ should set to the an attribute name string followed by a colon followed by hex representation for the blue, green and red color values, e.g.
AttributeID:\&hbbggrr
The available attributes (not case sensitive) for which colors can be set are as follows:
| | |
|------|------|
| **AttributeID** | **Description** |
| SETCOLOR\_BACKGROUND | Background (area outside the calendars but inside the control borders) |
| SETCOLOR\_MONTHBK | Background for the calendar(s) |
| SETCOLOR\_TEXT | Color of the text within a month (days) |
| SETCOLOR\_TITLEBK | Background of the title area |
| SETCOLOR\_TITLETEXT | Title text color |
| SETCOLOR\_HDRTRAILINGTEXT | Text color for the display header day and trailing day text (leading and trailing days from previous and following months) |
**Example**
ctext\$ = "SETCOLOR\_MONTHBK:\&heecc88"
xcall AUI, AUI\_CONTROL, CTLOP\_CHG, ctlid, ctext\$, MBST\_TEXTONLY
**Visibility Issues**
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.
**History**
March 2024, A-Shell 7.0.1757: ASHMONTHCAL control enhancement: you can now set various color attributes for the control.