Microsoft KB Archive/62204

VioSetCurPos to Position Cursor in Protected Mode

PSS ID Number: Q62204 Article last modified on 06-07-1990

3.00 3.00a OS/2

Summary: Microsoft COBOL versions 3.00 and 3.00a can call an OS/2 API function to position the cursor in OS/2 protected mode. These versions of COBOL can call API functions directly by prefixing their names with a double underscore. This article shows how to make a call to the OS/2 API function VioSetCurPos and gives an example. This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS OS/2.

More Information: The API function VioSetCurPos requires that the following data items be passed to it for input: WORD (2 bytes) Y (row) coordinate WORD (2 bytes) X (column) coordinate WORD (2 bytes) Video handle (0 = default) The maximum values for Y and X depend on the current display mode, but the upper-left corner of the screen is always (0,0). When calling non-COBOL functions and subprograms such as OS/2 API functions, a WORD has a picture clause of “9(4) COMP-5” and must be passed using the BY VALUE clause. By default, COBOL passes BY REFERENCE. Also, API functions use the Pascal calling convention, which is the reverse of COBOL’s. COBOL uses the C calling convention, so the parameters must be mentioned in the reverse order when calling API functions. 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.00 or 3.00a. For more information on VioSetCurPos, see Page 613 of “Advanced OS/2 Programming,” by Ray Duncan (Microsoft Press, 1989). The following sample program displays messages in different parts of the screen, using the API function VioSetCurPos to position the cursor associated with the default video handle. To compile and link the program, use the following: pcobol setcursor; link /nop setcursor,,,pcobol doscalls;

Code Example
$SET ANS85 IDENTIFICATION DIVISION. PROGRAM-ID. SETCURSOR. DATA DIVISION. WORKING-STORAGE SECTION. * Row, initialize to upper-most. 01 Y       PIC 9(4) COMP-5 VALUE 0. * Column, initialize to left-most. 01 X       PIC 9(4) COMP-5 VALUE 0. * Video handle, initialize to default. 01 Handle  PIC 9(4) COMP-5 VALUE 0. * Used to poll the keyboard. 01 AnyKey  PIC 99   COMP-X VALUE 0. PROCEDURE DIVISION. *   Clear the screen CALL X&quot;E4&quot;. *   Call the API function to position the cursor at  *    upper-left corner. CALL &quot;__VioSetCurPos&quot; USING BY VALUE Handle, BY VALUE X,                                  BY VALUE Y.       DISPLAY &quot;UPPER-LEFT CORNER&quot; WITH NO ADVANCING. *   Position cursor at lower-left corner. MOVE 24 TO Y.      CALL &quot;__VioSetCurPos&quot; USING BY VALUE Handle, BY VALUE X,                                  BY VALUE Y.       DISPLAY &quot;BOTTOM-LEFT CORNER&quot; WITH NO ADVANCING. MOVE 12 TO Y.      MOVE 35 TO X.       CALL &quot;__VioSetCurPos&quot; USING BY VALUE Handle, BY VALUE X,                                  BY VALUE Y.       DISPLAY &quot;CENTERED&quot;. *   When AnyKey NOT = 0, the user pressed a key PERFORM UNTIL AnyKey NOT = 0 *      Check if key is in the buffer CALL X&quot;D9&quot; USING AnyKey END-PERFORM. STOP RUN. Copyright Microsoft Corporation 1990.