Opening Child Windows

In your QuickWin program, you may want to open new windows (child windows) in which to display your program's data.

Depending on your needs, you can use one of two QuickWin functions to open new child windows. The _wopen function is a low-level routine that returns a file handle, which you can use for window I/O or to call several other QuickWin functions, such as _wsetsize, _wsetfocus, and _wsetscreenbuf. You can perform I/O in this kind of window with C library functions such as _write and _read. Using these functions is explained later in this section.

In order to write to a window or read from it as a stream, you need a file pointer, of type FILE *. The _fwopen function is a high-level routine that returns a file pointer you can pass to standard input/output routines, such as fprintf and fscanf, which require a stream argument.

Note:

If you open windows with _fwopen, you can use the standard fileno macro to obtain a file handle for use with QuickWin and other routines that require a handle argument. Do not use such a handle with the _wclose function, however.

Both _wopen and _fwopen require arguments of type _wopeninfo and _wsizeinfo. These are defined as C structures in the Windows version of IO.H. The _wopeninfo structure is declared as follows:

struct _wopeninfo {

unsigned int _version;

const char _far * _title;

long _wbufsize;

};

The _version field contains the Windows version number. Use the constant _WINVER, declared in IO.H. The _title field holds a null-terminated string. This is the title of your window. The _wbufsize field contains the size of the window screen buffer (in bytes). The default is 2,048.

The _wsizeinfo struct is declared as

struct _wsizeinfo {

unsigned int _version; /* Use _WINVER */

unsigned int _type; /* Size for window */

unsigned int _x; /* Upper left x coordinate */

unsigned int _y; /* Upper left y coordinate */

unsigned int _h; /* Height of window */

unsigned int _w; /* Width of window */

};

The _version field contains the Windows version number. Use the constant _WINVER. For use in opening windows, the _type field specifies the size of the window as one of the following constants:

_WINSIZEMIN

Minimizes the window

_WINSIZEMAX

Maximizes the window

_WINSIZECHAR

Uses the listed coordinates in the x, y, h, w fields for the window size

If you specify a _type field of _WINSIZEMIN or _WINSIZEMAX, you can leave the _x, _y, _h, and _w fields empty.

To open a document window, first declare variables of the _wopeninfo and _wsizeinfo types and fill in their fields. Then call either _wopen or _fwopen.

The _wopen function also takes a third argument of type int, specifying the access flags. Flags accepted are _O_BINARY, _O_RDONLY, _O_RDWR, _O_TEXT, and _O_WRONLY. Note that _wopen does not allow the _O_CREAT, _O_TRUNC, or _O_EXCL flags.

The _fwopen function takes an argument of type pointer to char to specify stream mode. The _fwopen function accepts the following mode values: “r”, “w”,“r+”, and “w+”. You can also append a “t” (for text) or a “b” (for binary) to the mode string.

If you pass NULL for either the _wsizeinfo or _wopeninfo arguments, the _fwopen function uses default values. The _wopen function works similarly, except that the _wopeninfo argument cannot be NULL. You must pass a pointer to a _wopeninfo structure.

The _wopen function returns an integer file handle to the new window if successful, or –1 if not. The _fwopen function returns a stream pointer to the new window if successful, or NULL if not.