Source Code
#include <ncurses.h>
int main()
{
FILE *wfile;
WINDOW *win;
int r;
initscr();
start_color();
init_pair(1,COLOR_WHITE,COLOR_BLUE);
refresh();
/* Crete and show window */
win = newwin(3,10,7,30);
wbkgd(win,COLOR_PAIR(1));
box(win,0,0);
mvwaddstr(win,1,2,"Window");
wrefresh(win);
getch();
/* open file */
wfile = fopen("window.win","w");
if( wfile==NULL )
{
endwin();
puts("File creation error");
return(1);
}
/* write window data */
r = putwin(win,wfile);
fclose(wfile);
addstr("Window data written");
refresh();
getch();
endwin();
return(0);
}
Output Screenshot

Notes
* Only the window data from window win is written to a file, not the entire screen.
* My default terminal setting shows orange text (as you see throughout this site). That's because I was fond of amber monitors back in the day. Still, the standard screen output for this code is white text. That's probably an effect of the start_color() function; though a color pair isn't initialized for the standard screen, I believe start_color() resets the terminal defaults.
Copyright © 1997-2025 by QPBC.
All rights reserved
