Microsoft KB Archive/62890

How to Toggle Cursor On/Off in COBOL Using OS/2 API Function

PSS ID Number: Q62890 Article last modified on 06-13-1990

3.00 3.00a OS/2

Summary: Microsoft COBOL versions 3.00 and 3.00a protected mode programs can call the OS/2 API function VioSetCurType to toggle the cursor on and off. These versions of COBOL can call API functions directly, prefixing their names with a double underscore. This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS OS/2.

More Information: VioSetCurType requires that the following data items be passed to it:

“StartLine” and “EndLine” are not important in toggling the cursor on and off. They refer to the desired starting and ending scan lines (where one line is a pixel high) of the cursor and can be manipulated to change its shape. Also, “Width” is not important here, and should be initialized to the default cursor width of 0. The field “Attribute” must be set to -1 to turn the cursor off and 0 to turn it back on. Since -1 has a two’s-complement binary representation of “1111111111111111”, the number 65.535 (which also has all bits set) can be used to represent -1 in a data item with a picture clause of 9(4) COMP-5. Since the specification requires a pointer to the first parameter, it must be passed using the BY REFERENCE clause. It is also worthy to note that a WORD (the type for the second parameter) has a picture clause of “9(4) COMP-5”. Remember also that API functions use a calling convention that is the reverse of COBOL’s, so the parameters must be passed in reverse order. For more information on calling OS/2 API functions from COBOL 3.00 and 3.00a, see the file OS2API.DOC included with COBOL 3.00a. For more information on VioSetCurType, see Page 613 of “Advanced OS/2 Programming,” by Ray Duncan (Microsoft Press, 1989). The sample program below (CURSOR.CBL) toggles the cursor off then back on. It sets the starting and ending scan lines at 6 and 7 respectively, because those numbers are valid for all video cards. For example, numbers in the range of 0-15 can be used for VGA, but other video cards (namely CGA) have a range of 0-7. To compile and link the program, use the following: pcobol cursor; link /nop cursor,,,pcobol doscalls;

Code Example
$SET ANS85 DATA DIVISION. WORKING-STORAGE SECTION. 01 Buffer. *  Set starting scan line of cursor to 6. 05 StartLine  PIC 9(4) COMP-5 VALUE 6. *  Set ending scan line of cursor to 7. 05 EndLine    PIC 9(4) COMP-5 VALUE 7. *  Set width of cursor to 0 (default) 05 Width      PIC 9(4) COMP-5 VALUE 0. *  Set attribute of cursor to invisible. 05 Attribute  PIC 9(4) COMP-5 VALUE 65535. * Default video handle is 0. 01 VideoHandle   PIC 9(4) COMP-5 VALUE 0. * Used to poll keyboard and get next key. 01 AnyKey        PIC 99   COMP-X VALUE 0. PROCEDURE DIVISION. *   Clear the screen. CALL X&quot;E4&quot;. DISPLAY &quot;Cursor is on by default, hit key to continue&quot;. *   Wait until a key is pressed. PERFORM UNTIL AnyKey NOT = 0 CALL X&quot;83&quot; USING AnyKey END-PERFORM. MOVE 0 TO AnyKey. *   Turn cursor off. CALL &quot;__VioSetCurType&quot; USING BY VALUE VideoHandle, BY REFERENCE Buffer. DISPLAY &quot;Cursor is now off, hit key to continue&quot;. *   Wait until a key is pressed. PERFORM UNTIL AnyKey NOT = 0 CALL X&quot;83&quot; USING AnyKey END-PERFORM. MOVE 0 TO AnyKey. *   Turn cursor back on. MOVE 0 TO Attribute. CALL &quot;__VioSetCurType&quot; USING BY VALUE VideoHandle, BY REFERENCE Buffer. DISPLAY &quot;Cursor is back on, hit key to end&quot;. *   Wait until a key is pressed. PERFORM UNTIL AnyKey NOT = 0 CALL X&quot;83&quot; USING AnyKey END-PERFORM. STOP RUN. Copyright Microsoft Corporation 1990.