Bridges > COM Import Bridge and ActiveX > ActiveX Controls > Example Calendar Control

# Example Calendar Control

This example uses an ActiveX control that displays a calendar interface. The control, contained in the file mscal.ocx, is installed along with a typical installation of Microsoft Office 97, and may also be present on your system if you have upgraded to a more recent version of Microsoft Office. If the control is not present on your system (you’ll know the control is not present if the example code does not display a calendar), you can download a the control as part of a package of sample ActiveX controls included in the file actxsamp.exe, discussed in Microsoft Knowledge Base Article 165437.

If you download the control, place the file mscal.exe in a known location and execute the file; you will be prompted for a directory in which to place mscal.ocx. Open a command prompt window in the directory you chose and register the control as described in Registering COM Components on a Windows Machine.

The calendar control has the program ID:

MSCAL.Calendar.7

and the class ID:

{8E27C92B-1264-101C-8A2F-040224009C02}

Note: This example, ActiveXCal.pro, is included in the examples\doc\bridges\COM subdirectory of the IDL distribution and develops an IDL routine called ActiveXCal that illustrates use of the calendar ActiveX control within an IDL widget hierarchy. Run the example procedure by entering ActiveXCal at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT ActiveXCal.pro.

1. Create the ActiveXCal procedure. (Remember that in the ActiveXCal.pro file, this procedure occurs last.)

PRO ActiveXCal

2. Create a top-level base widget to hold the ActiveX control.

wBase = WIDGET_BASE(COLUMN = 1, SCR_XSIZE = 400, $

TITLE='IDL ActiveX Widget Calendar Control')

3. Create base widgets to hold labels for the selected month, day, and year. Set the initial values of the labels.

wSubBase = WIDGET_BASE(wBase, /ROW)
wVoid = WIDGET_LABEL(wSubBase, value = 'Month: ')

wMonth = WIDGET_LABEL(wSubBase, value = 'October')

wSubBase = WIDGET_BASE(wBase, /ROW)
wVoid = WIDGET_LABEL(wSubBase, VALUE = 'Day: ')

wDay = WIDGET_LABEL(wSubBase, VALUE = '22')

wSubBase = WIDGET_BASE(wBase, /ROW)
wVoid = WIDGET_LABEL(wSubBase, VALUE = 'Year: ')
wYear = WIDGET_LABEL(wSubBase, VALUE = '1999')

4. Instantiate the ActiveX Control, using the control’s class ID.

wAx=WIDGET_ACTIVEX(wBase,

'{8E27C92B-1264-101C-8A2F-040224009C02}')

5. Realize the top-level base widget.

WIDGET_CONTROL, wBase, /REALIZE

6. Set the top-level base’s user value to an anonymous structure containing widget IDs of the month, day, and year label widgets.

WIDGET_CONTROL, wBase, $

SET_UVALUE = {month:wMonth, day:wDay, year:wYear}

7. Retrieve the object ID of the IDLcomActiveX object that encapsulates the ActiveX control. Use the GetProperty method to retrieve the current values of the month, day, and year from the control.

WIDGET_CONTROL, wAx, GET_VALUE = oAx
oAx->GetProperty, month=month, day=day, year=year

8. Set the values of the label widgets to reflect the current date, as reported by the
   ActiveX control.

WIDGET_CONTROL, wMonth, SET_VALUE=STRTRIM(month, 2)

WIDGET_CONTROL, wDay, SET_VALUE=STRTRIM(day, 2)

WIDGET_CONTROL, wYear, SET_VALUE=STRTRIM(year, 2)

9. Call XMANAGER to manage the widget events, and end the procedure.

XMANAGER, 'ActiveXCal', wBase
END

10. Now create an event-handling routine for the calendar control. (Remember that in the ActiveXCal.pro file, this procedure occurs before the ActiveXCal procedure.)

PRO ActiveXCal_event, ev

11. The ActiveX widget is the only widget in this application that generates widget events, so the ID field of the event structure is guaranteed to contain the widget ID of that widget. Use the GET_VALUE keyword to retrieve an object reference to the IDLcomActiveX object that encapsulates the control.

WIDGET_CONTROL, ev.ID, GET_VALUE = oCal

12. The user value of the top-level base widget is an anonymous structure that holds the widget IDs of the month, day, and year label widgets (see step 6 above). Retrieve the structure into a variable named state.

WIDGET_CONTROL, ev.TOP, GET_UVALUE = state

13. Use the GetProperty method on the IDLcomActiveX object to retrieve the current values of the month, day, and year from the calendar control.

oCal->GetProperty, month=month, day=day, year=year

14. Use WIDGET_CONTROL to set the values of the month, day, and year label widgets.

WIDGET_CONTROL, state.month, SET_VALUE = STRTRIM(month,2)

WIDGET_CONTROL, state.day, SET_VALUE = STRTRIM(day,2)

WIDGET_CONTROL, state.year, SET_VALUE = STRTRIM(year,2)

15. Call HEAP_FREE to ensure that dynamic portions of the event structure are released, and end the procedure.

HEAP_FREE, ev
END

Running the ActiveXCal procedure displays a widget that looks like the following: