OS/2 COBOL Program to Change Cursor Shape Using OS/2 API
PSS ID Number: Q63271 Article last modified on 06-25-1990
3.00 3.00a OS/2
Summary: In Microsoft COBOL versions 3.00 and 3.00a, you can change the shape of the hardware text cursor by calling the OS/2 API function VioSetCurType(). These versions of COBOL can call API functions directly, prefixing their names with a double underscore. The information in this article 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:
Data Item | Description |
---|---|
PTR BUFFER | Where BUFFER is a group item composed of the following |
elementary items: | |
01 Buffer. | |
05 StartLine PIC 9(4) COMP-5. | |
05 EndLine PIC 9(4) COMP-5. | |
05 Width PIC 9(4) COMP-5. | |
05 Attribute PIC 9(4) COMP-5. | |
WORD | Video Handle (0=default) |
“StartLine” and “EndLine” refer to the desired starting and ending scan lines (where a line is 1 pixel high) of the cursor and can be manipulated to change its shape. These fields can be a number in the range of 0-7 for CGA, 0-13 for EGA, and 0-15 for VGA. After the call, only the specified range of scan lines that make up the cursor will be displayed. “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 the specification requires a pointer to the first parameter, this parameter must be passed using the BY REFERENCE clause. Also note that a WORD (the type for the second parameter) has a picture clause of “9(4) COMP-5”. The parameters also must be passed in reverse order because API functions use a calling convention that is the reverse of COBOL’s. 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 following sample program (HEIGHT.CBL) allows you to increase or decrease the height of the cursor via the keyboard. Use the following to compile and link the program: pcobol height; link /nop height adis adisinit adiskey,,,pcobol doscalls;
Code Example
$SET ANS85 DATA DIVISION. WORKING-STORAGE SECTION. 01 Buffer. * Set starting scan line to 14 (6 for CGA, 12 for EGA). 05 StartLine PIC 9(4) COMP-5 VALUE 14. * Set ending scan line to 15 (7 for CGA, 13 for EGA). 05 EndLine PIC 9(4) COMP-5 VALUE 15. * Set width of cursor to 0 (default). 05 Width PIC 9(4) COMP-5 VALUE 0. * Set attribute of cursor to visible. 05 Attribute PIC 9(4) COMP-5 VALUE 0. * Default video handle is 0. 01 VideoHandle PIC 9(4) COMP-5 VALUE 0. * Used to get next key from keyboard buffer. 01 AnyKey PIC 99 COMP-X VALUE 0. * Starting height of cursor is 2 lines. 01 Height PIC 99 VALUE 2. PROCEDURE DIVISION. * Clear the screen and display prompt. CALL X"E4". DISPLAY "l = lower cursor height" AT 1325. DISPLAY "r = raise cursor height" AT 1425. DISPLAY "q = quit" AT 1525. DISPLAY "Cursor height is 02" AT 1125. * Program will end if user hits 'q'. PERFORM UNTIL AnyKey = 113 * Get next key (if any) from buffer. CALL X"83" USING AnyKey EVALUATE AnyKey * When AnyKey = 'l', lower height of cursor by 1 line * only if it is greater than the minimum 1 line high. WHEN 108 IF Height > 1 THEN COMPUTE Height = Height - 1 COMPUTE StartLine = StartLine + 1 END-IF * When AnyKey = 'r', raise height of cursor by 1 line * only if it is less than the maximum 16 lines high. * Maximum for CGA is 8, 14 for EGA. WHEN 114 IF Height < 16 THEN COMPUTE Height = Height + 1 COMPUTE StartLine = StartLine - 1 END-IF END-EVALUATE * Display current height of cursor and call API function * to make any changes if they occurred. DISPLAY Height AT 1142 CALL "__VioSetCurType" USING BY VALUE VideoHandle, BY REFERENCE Buffer END-PERFORM. * Clear screen and end program. CALL X"E4". STOP RUN.
Copyright Microsoft Corporation 1990.