DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
ETI program examples

The window program

This example program demonstrates the use of multiple windows. The main display is kept in stdscr. When you want to put something other than what is in stdscr on the physical terminal screen temporarily, a new window is created covering part of the screen. A call to wrefresh for that window causes it to be written over the stdscr image on the terminal screen. Calling refresh on stdscr results in the original window being redrawn on the screen. Note the calls to the touchwin routine (which we have not discussed -- see the curses(3ocurses) manual pages) that occur before writing out a window over an existing window on the terminal screen. This routine prevents screen optimization in a curses program. If you have trouble refreshing a new window that overlaps an old window, it may be necessary to call touchwin for the new window to get it completely written out.

#include <ocurses.h>

WINDOW *cmdwin;

main()

{

int i, c; char buf[120]; void exit();

initscr(); nonl(); noecho(); cbreak();

cmdwin = newwin(3, COLS, 0, 0); /* top 3 lines */ for (i = 0; i < LINES; i++) mvprintw(i, 0, "This is line %d of stdscr", i);

for (;;)

{ refresh(); c = getch(); switch (c)

{

case 'c': /* Enter command from keyboard */ werase(cmdwin); wprintw(cmdwin, "Enter command:"); wmove(cmdwin, 2, 0); for (i = 0; i < COLS; i++) waddch(cmdwin, '-'); wmove(cmdwin, 1, 0); touchwin(cmdwin); wrefresh(cmdwin); wgetstr(cmdwin, buf); touchwin(stdscr);

/* * The command is now in buf. * It should be processed here. */

case 'q': endwin(); exit(0); }

}

}


Next topic: The colors program
Previous topic: The two program

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004