Microsoft KB Archive/62457

From BetaArchive Wiki

Call API Function to Change Border Color in Protected Mode

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

3.00 3.00a OS/2

Summary: Microsoft COBOL Compiler versions 3.00 and 3.00a protected mode programs can call the OS/2 API function VioSetState() to change the border color. This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS OS/2.

More Information: VioSetState() requires the following parameters to be passed to it:

Parameter Description
PTR BUFFER Where BUFFER is a group item composed of the following
elementary items:
01 Buffer.
05 BufferLength PIC 9(4) COMP-5 VALUE 6.
05 Operation PIC 9(4) COMP-5 VALUE 1.
05 BorderColor PIC 9(4) COMP-5.
WORD V ideo handle (0 = default)

“BufferLength” holds the length, in bytes, of Buffer, which is 6. “Operation” contains a 1, which informs VioSetState() to change the border color. “BorderColor” holds the number of the color to change the border to. Remember that a WORD (2 bytes) in COBOL has a picture clause of “9(4) COMP-5”. Since the specification requires a pointer to the first parameter, the BY REFERENCE clause will be used on it in the CALL to VioSetState(). The second parameter does not require a pointer, so the BY VALUE clause must be used for it to be passed by its value. Remember also that API functions use a calling convention that is the reverse of COBOL’s, so the parameters must be passed in the 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 3.00a. For more information on VioSetState(), see Page 616 of “Advanced OS/2 Programming,” by Ray Duncan (Microsoft Press, 1989). The sample program below (BORDER.CBL) allows you to circulate through the 16 default text-mode colors, changing the color of the border to each in turn. To compile and link the program, do the following: pcobol border; link /nop border adis adisinit adiskey,,,pcobol doscalls;

Code Example

  $SET ANS85
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 Buffer.
  *   Length of Buffer is 6.
      05 BufferLength   PIC 9(4) COMP-5 VALUE 6.
  *   Operation 1 for VioSetState changes border color.
      05 Operation      PIC 9(4) COMP-5 VALUE 1.
  *   Color to change border to, start at 0.
      05 BorderColor    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 keystroke from buffer.
   01 AnyKey            PIC 9(2) COMP-X VALUE 0.
   PROCEDURE DIVISION.
  *    Clear the screen and display prompt.
       CALL X"E4".
       DISPLAY "Hit space to change border color, 'q' to quit."
               AT 1317.
  *    Program will terminate when 'q' is entered.
       PERFORM UNTIL AnyKey = 113
  *       Get next keystroke from buffer.
          CALL X"83" USING AnyKey
  *       If space bar hit, change border color.
          IF AnyKey = 32 THEN
  *          Increment next border color until it gets to 15,
  *          then start over at 0.
             IF BorderColor < 15 THEN
                COMPUTE BorderColor = BorderColor + 1
             ELSE
                MOVE 0 TO BorderColor
             END-IF
  *          Call the API function.
             CALL "__VioSetState" USING BY VALUE VideoHandle,
                                        BY REFERENCE Buffer
          END-IF
       END-PERFORM.
  *    Clear screen and end program.
       CALL X"E4".
       STOP RUN.

Copyright Microsoft Corporation 1990.