Converting your code to use the windowing API

This topic describes the straight conversion method of converting your application to use the windowing subroutines. This method uses one window for all screen I/O, and it doesn’t use any UI Toolkit features. The conversion only involves a few steps, but the improvement in speed can be significant.

The straight conversion strategy assumes the following about your application:

If your application doesn’t meet these criteria, your conversion could be more complex.

Converting your code

You need to add or change code in four places: start-up subroutine, input subroutine, output subroutine, and message displays.

Start-up subroutine

1. Call W_INIT to initialize the windowing system and test whether the system has already been initialized.
2. Define a global data section with a variable for the window ID.
3. Create a borderless 24 x 80 window and place it on the screen at position (1,1).

Input subroutine

1. Include the global data section that has the global window ID.
2. Change your Synergy DBL READS and ACCEPT statements to use W_DISP with the WD_READS and WD_ACCEPT functions. For example, instead of this:
reads(TTCHN, avar)
accept(TTCHN, achr)

You would use this:

xcall w_disp(g_wndid, WD_READS, avar)
xcall w_disp(g_wndid, WD_ACCEPT, achr)

Output subroutine

1. Include the global data section that has the global window ID.
2. Change your Synergy DBL WRITES and DISPLAY statements to use W_DISP. Use the WD_FIELD function for decimal displays and the WD_ANSI function for ANSI escape sequences. For example, instead of
display(TTCHN, avar1, avar2, dvar)
writes(TTCHN, avar)

You would use this:

xcall w_disp(g_wndid, WD_WRITES, avar)
xcall w_disp(g_wndid, avar1, avar2, WD_FIELD, dvar)

Message displays

Whenever you display a message on the screen that isn’t followed by terminal input, use WD_UPDT or W_UPDT to update the screen.

Updating the screen

The screen is updated implicitly by an input function or explicitly by calling W_UPDT or the WD_UPDT function of W_DISP.


Do not use W_UPDT or W_DISP(WD_UPDT) after each screen change: it slows down screen I/O. The only time you need to use W_UPDT is when you change the screen and then don’t do any screen input.

For example, if you display a “Working…Please Wait” message, call W_UPDT immediately after making the display (or use the WD_UPDT function in the W_DISP call) so you update the screen to show the message. If you don’t explicitly update the screen in this instance, the user may never see the message!


Here’s an example of the additions you can make to your start-up subroutine:

global data section gwindow
    g_wndid     ,i4
.define TTCHN, 1
    iflg        ,i4             ;Initialization test flag
    xcall w_init(0, TTCHN, 4, 24, 80, iflg)
    if (.not.iflg)              ;Is it already set up?
      begin                     ;No, create it w/o border, place it
        xcall w_proc(WP_CREATE, g_wndid, "main", 24, 80)
        xcall w_brdr(g_wndid, WB_OFF)
        xcall w_proc(WP_PLACE, g_wndid, 1, 1)