ActiveX Examples

Use of the Windows Media Player control is demonstrated in an AcuBench sample project located in the Support area of the Micro Focus Web site. To download the project, go to: https://supportline.microfocus.com/examplesandutilities/index.aspx, and select ACUCOBOL-GTĀ® Samples > Graphical User Interface (GUI) Sample Programs > Media_Player.zip.

Following is an excerpt of the COPY file generated by AXDEFGEN for Microsoft's Calendar Control 8.0. The COPY file includes object names so that the compiler can distinguish between two classes with the same name in different objects. For example, you might want to create an "Application of Word" and an "Application of Excel" in the same COBOL program. In the Calendar COPY file, the line "OBJECT @MSACAL" specifies the object name.

* CAL.DEF - ActiveX control definitions for MSACAL
* Generated: Tuesday, June 22, 1999


    OBJECT @MSACAL

* Calendar control

*** Primary Interface ***

* Calendar
     CLASS @Calendar
         CLSID, 8E27C92B-1264-101C-8A2F-040224009C02
         NAME, "Calendar"
         PRIMARY-INTERFACE
         ACTIVE-X-CONTROL
         DEFAULT-INTERFACE, "ICalendar"
         DEFAULT-SOURCE, "DCalendarEvents"
* BackColor
         PROPERTY-GET, -501, @BackColor
                 RETURNING "OLE_COLOR"
* BackColor
         PROPERTY-PUT, -501, @BackColor,
             "OLE_COLOR (Property Value)"
* Day
         PROPERTY-GET, 17, @Day
                 RETURNING "short"
* Day
         PROPERTY-PUT, 17, @Day,
             "short (Property Value)"
* DayFont
         PROPERTY-GET, 1, @DayFont
                 RETURNING "IFontDisp*"
* DayFont
         PROPERTY-PUT, 1, @DayFont,
             "IFontDisp* (Property Value)"
* DayFontColor
         PROPERTY-GET, 2, @DayFontColor
                 RETURNING "OLE_COLOR"
* DayFontColor
         PROPERTY-PUT, 2, @DayFontColor,
             "OLE_COLOR (Property Value)"
* NextDay
         METHOD, 22, @NextDay
* NextMonth
         METHOD, 23, @NextMonth
* NextWeek
         METHOD, 24, @NextWeek
* NextYear
         METHOD, 25, @NextYear
* PreviousDay
         METHOD, 26, @PreviousDay
* PreviousMonth
         METHOD, 27, @PreviousMonth
* PreviousWeek
         METHOD, 28, @PreviousWeek
* PreviousYear
         METHOD, 29, @PreviousYear
* Refresh
         METHOD, -550, @Refresh
* Today
         METHOD, 30, @Today
* AboutBox
         METHOD, -552, @AboutBox
* Click
         EVENT, -600, @CalendarClick
*            No Parameters
* DblClick
         EVENT, -601, @CalendarDblClick
*            No Parameters
* KeyDown
         EVENT, -602, @CalendarKeyDown
*            2 Parameters
                 short* KeyCode
                 short Shift
* KeyPress
         EVENT, -603, @CalendarKeyPress
*            1 Parameter
*                short* KeyAscii
* KeyUp
         EVENT, -604, @CalendarKeyUp
*            2 Parameters
*                short* KeyCode
*                short Shift
* BeforeUpdate
         EVENT, 2, @CalendarBeforeUpdate
*            1 Parameter
*                short* Cancel
* AfterUpdate
         EVENT, 1, @CalendarAfterUpdate
*            No Parameters
* NewMonth
         EVENT, 3, @CalendarNewMonth
*            No Parameters
* NewYear
         EVENT, 4, @CalendarNewYear
*            No Parameters

After generating the COPY file, you may create and use a Calendar control. You can add the control to your Screen Section as described in Adding ActiveX Controls or COM Objects to Your COBOL Program, or you can use the DISPLAY statement in the Procedure DivisioN to create the control. Note that the following two statements are equivalent:

    DISPLAY Calendar HANDLE IN my-cal.
    DISPLAY Calendar OF MSACAL HANDLE IN my-cal.

Here is an example of how you might update your Procedure Division to create, and then modify, the control:

* Declare the calendar control's handle.
77 CALENDAR-1 USAGE IS HANDLE OF Calendar.
...
* Declare the @KeyPress event parameter
77 KEY-ASCII PIC X USAGE COMP-X.
77 KEY-CHAR PIC X REDEFINES KEY-ASCII.
...
* Calendar @Value is the current date
01 DATE-1
    03 MONTH PIC 99.
    03 FILLER PIC X VALUE '/'.
    03 DAY PIC 99.
    03 FILLER PIC X VALUE '/'.
    03 YEAR PIC 9999.
...
* Create an instance of the calendar control
       DISPLAY Calendar LINE 4 COLUMN 6 LINES 10 SIZE 40
               EVENT PROCEDURE IS CALENDAR-EVENT-HANDLER
               HANDLE IN CALENDAR-1.
...
* Set the calendar's "day" font to Courier 10 pt Bold
       USE CALENDAR-1 DayFont
           MODIFY Name = "Courier" Size = 10 Bold = 1.
...
* Set the calendar's year to 2000
       MODIFY CALENDAR-1 Year = 2000.
...
* Invoke the NextDay method
       MODIFY CALENDAR-1 NextDay.
...
* Invoke the PreviousDay method
       MODIFY CALENDAR-1 PreviousDay.
...
* Handle events
...
CALENDAR-EVENT-HANDLER.
       EVALUATE EVENT-TYPE
           WHEN MSG-AX-EVENT
               EVALUATE EVENT-DATA-2
                   WHEN CalendarBeforeUpdate
* Don't allow years >= 2000
                       INQUIRE EVENT-CONTROL-HANDLE 
                          @Value IN DATE-1
                       IF YEAR OF DATE-1 >= 2000
* Cancel the update (set the 'Cancel' parameter to 1)
                           CALL "C$SETEVENTDATA" USING
                           EVENT-CONTROL-HANDLE, 1
                       END-IF
                   WHEN CalendarKeyPress
* Stop run if the user presses 'X'
                       CALL "C$GETEVENTDATA" USING 
                       EVENT-CONTROL-HANDLE, KEY-ASCII
                   IF KEY-CHAR = 'X' STOP RUN END-IF
...