Keywords: lpg

Next: 8.6 Output Up: 8 Character Cell Graphics Previous: 8.4 Initializing

# 8.5 Windows

Windows can be created, deleted, moved, copied, touched, duplicated and more.

- `WINDOW *newwin(nlines, ncols, begy, begx)`
  `begy` and `begx` are the window coordinates of the upper left corner. `nlines` is an integer with the number of lines and `ncols` is an integer with the number of columns.

  Figure 8.1: Ncurses - scheme for newwin

  The upper left corner of our window is in line 10 and column 10 and the window has 10 lines and 60 columns. If `nlines` is zero, the window will have LINES-begy rows. In the same way the, window will have COLS-begx columns when `ncols` is zero.

  When you call newwin(...) with all argument zero:

  the opened window will have the size of the screen.

  With and we can open windows in the middle of the screen, whatever dimension it has:

  This will open a window with 22 lines and 70 rows in the middle of the screen. Check the screen size before opening windows. In the Linux console we have 25 or more lines and 80 or more columns, but in xterms this may not be the case (they're resizable).

  Alternatively, use and to adapt two windows to the screen size:

  See .c in the example directory for more explanations.

- `int delwin(win)`
  Delete the window `win`. When there are subwindows delete them before `win`. It will free up all resources occupied by `win`. Delete all windows you have opened before calling endwin().
- `int mvwin(win, by, bx)`
  Will move a window to the coordinates `by,bx`. If this means moving the window beyond the edges of the screen, nothing is done, and ERR is returned.
- `WINDOW *subwin(origwin, nlines, ncols, begy, begx)`
  Returns a subwindow in the middle of `origwin`. When you change one of the two windows (`origwin` or the new one) this change will be reflected in both windows. Call touchwin(origwin) before the next refresh().

  `begx` and `begy` are relative to the screen, not to `origwin`.

- `WINDOW *derwin(origwin, nlines, ncols, begy, begx)`
  The same as subwin(...) except that `begx` and `begy` are relative to the window `origwin` than to the screen.
- `int mvderwin(win, y, x)`
  Will move `win` inside its parent window. (Note: not implemented yet.)
- `WINDOW *dupwin(win)`
  Duplicate the window `win`.
- `int syncok(win, bf)`
  `void wsyncup(win)`
  `void wcursyncup(win)`
  `void wsyncdown(win)`
  (Note: not implemented yet.)
- `int overlay(win1, win2)`
  `int overwrite(win1, win2)`
  overlay(...) will copy all text from `win1` to `win2` without copying blanks. overwrite(...) does the same, but copies blanks, too.
- `int copywin(win1, win2, sminrow, smincol, dminrow, dmincol,`
  `dmaxrow, dmaxcol, overlay)`
  Similar to overlay(...) and overwrite(...), but provides control over what region of the window to copy.

Next: 8.6 Output Up: 8 Character Cell Graphics Previous: 8.4 Initializing