_fwopen

Description

Opens a new file stream for a QuickWin window.

#include <stdio.h>

FILE * _fwopen( struct _wopeninfo *wopeninfo,
struct _wsizeinfo *wsizeinfo, char * mode );

wopeninfo Pointer to a _wopeninfo structure  
wsizeinfo Pointer to a _wsizeinfo structure  
mode Type of access permitted  

Remarks

The _fwopen function is a high-level call that opens a new QuickWin window, returning a file-stream pointer. This routine is used only in QuickWin programs; it is not part of the Windows API. For full details about QuickWin, see Chapter 8 of Programming Techniques (in the Microsoft C/C++ version 7.0 documentation set).

The _wopeninfo and _wsizeinfo structures, declared in STDIO.H, are used to pass window initialization information, including the window's initial size and position on the screen. You can pass NULL for these arguments to accept QuickWin defaults or declare variables of these two structure types and fill in their fields.

If you declare _wopeninfo and _wsizeinfo variables, assign the _WINVER macro to the _version field. _WINVER is the current QuickWin version, defined in STDIO.H.

For the _wopeninfo variable, assign a null-terminated string to the _title field containing the desired window title. You can also optionally set the size of the window's screen buffer in the _wbufsize field. The default is 2,048 bytes, but you can pass some other number or the value _WINBUFINF. This causes the buffer to be reallocated continually so that all window output is retained for scrolling.

For the _wsizeinfo variable, assign one of the following values to the _type field:

Value Meaning

_WINSIZEMIN Minimize the window
_WINSIZEMAX Maximize the window
_WINSIZECHAR Use character coordinates for the window size

If the type is _WINSIZECHAR, you must supply the _x, _y, _h, and _w values in the remainder of the structure. They specify the upper-left corner and the height and width of the window (in characters).

The mode parameter is a pointer to the stream I/O mode. The _fwopen function accepts the same mode values as the STDIO.H fopen function:

Type Description

"r" Opens for reading
"w" Opens for writing
"r+" Opens for both reading and writing
"w+" Opens for both reading and writing

In addition to the values listed above, one of the following characters can be included in mode to specify the translation mode for newline characters:

Mode Meaning

t Open in text (translated) mode
b Open in binary (untranslated) mode

If t or b is not given in mode, the translation mode is defined by the default-mode variable _fmode. If t or b is prefixed to the argument, the function fails and returns NULL. See “Input and Output” for a discussion of text and binary modes.

If _fwopen is successful, the returned stream can be passed to standard STDIO.H functions such as fread, fwrite, and fprintf. If you write to a stream and then read from it, or if you read from a stream and then write to it, call the STDIO.H rewind function between the I/O calls. To close an open window stream, call the STDIO.H function fclose. If you have opened a window with _fwopen, you can use the _fileno macro to obtain a file handle, which you can then pass to other QuickWin calls, such as _wsetscreenbuf or _wsetsize.

Return Value

If successful, the _fwopen function returns a stream pointer (FILE *) to the new window. A return value of NULL indicates an error.

Compatibility

Standards:None

16-Bit:QWIN

32-Bit:None

See Also

fclose, _fileno, _wabout, _wclose, _wgetfocus, _wgetscreenbuf, _wgetsize, _wmenuclick, _wopen, _wsetfocus, _wsetscreenbuf, _wsetsize, _wyield

Example

/* FOWPEN.C - Demonstrate opening QuickWin windows with _fwopen */

#include <io.h>

#include <stdio.h>

#define OPENFLAGS "w" /* Access permission */

void main( void )

{

struct _wopeninfo wininfo; /* Open information */

char wintitle[32] = "QuickWin "; /* Title for window */

FILE *wp; /* FILE ptr to window */

int nRes; /* I/O result */

/* Set up window info structure for _fwopen */

wininfo._version = _WINVER;

wininfo._title = wintitle;

wininfo._wbufsize = _WINBUFDEF;

/* Create a new window */

/* NULL second argument accepts default size/position */

wp = _fwopen( &wininfo, NULL, OPENFLAGS );

if( wp == NULL )

{

printf( "***ERROR: _fwopen\n" );

exit( -1 );

}

/* Write in the window */

nRes = fprintf( wp, "Hello, QuickWin!\n" );

/* Close the window */

nRes = fclose( wp );

exit( 0 );

}