Creating and using a virtual window is very similar to creating a basic window. Instead of using wn_def() to define the window, you use wn_vdef(). wn_vdef() takes all parameters used by wn_def(), and also accepts two additional parameters, which are used to specify the size of the memory screen.
The tutorial program wnv_basics.c, listed below, shows the steps to defining virtual window. Try it on your system. You will find it helpful to try the tutorial program before reading the explanation.
|
||
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
The example above illustrates the steps to creating and using virtual windows in your programs. They are as follows:
| 1 | Include the system header files. |
| 2 | Declare a pointer to a window structure. |
| 3 | Allocate and initialize the window structure with wn_vdef(). |
| 4 | Use the virtual window. |
| 5 | Free the memory for the window structure with wn_free(). |
An explanation of each step follows.
Step 1: Include the system header files.
To enable scrolling the virtual window, #include vv_wnkt.h, which links in the viewing event table. This header file automatically brings in vv_key.h and vv_sys.h.
As with all Vermont Views applications, you must include vv_main.h as the last Vermont Views header file in the application.
Step 2: Declare a pointer to a window structure.
To declare a variable that references a window structure, you declare the variable to be of type WINDOWPTR, which is a typedef for a pointer to a window structure.
Step 3: Allocate and initialize the window structure with wn_vdef().
Use wn_vdef() to allocate a window structure and define the initial values of the structure members. This function is explained in detail in Chapter 23, "About Windows." As a quick review, the call for wn_vdef() is as follows:
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The call to wn_vdef() is similar to wn_def(). For ms_rowq and ms_colq, specify the number of rows and columns to make the memory screen.
Step 4: Use the virtual window.
You can use any of the video output functions to write to the virtual window. The output is written to the window buffer, and starts at the location specified by the virtual cursor. The virtual cursor is initially set to (0, 0). When writing strings to the virtual window, the virtual cursor, by default, automatically advances in the memory screen.
Also by default, window tracking is turned ON. Automatic tracking means that the window write functions will automatically keep the virtual cursor of the buffer within the interior work area of the window. When the window is on the screen and the video output functions cause the position of the virtual cursor to change, the memory screen will automatically scroll so that the virtual cursor stays within the work area window and the output is visible.
In this example, the information is written before the window is displayed with wn_proc(). If the window is already on the screen when you write to it, output goes to the memory screen and then, by default, is automatically echoed to the physical screen.
Because we wish the display to start at the first line in the memory screen, we use the cs_mv() function to move the virtual cursor back up to the first row. For more information about cs_mv(), refer to Chapter 24, "Writing to Windows."
Step 5: Free the memory for the window structure with wn_free().
When you are through with the window, you can free the memory that was allocated for its structure with wn_free().