| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 
 |  
#include <iostream>
#include <ncurses.h>
#include <string>
#include <cstring>
using std::string;
 
WINDOW *create_newwin(int height, int width, int starty, int startx);
void destroy_win(WINDOW *local_win);
void print_position( WINDOW *local_win,int V , int H,string my_string);
 
int main()
{
WINDOW *my_win;
 
initscr();
if(has_colors() == FALSE)
	{
		endwin();
		std::cout << "le terminal ne supporte pas les couleurs fin du  programe"  << std::endl;
		return 1;
	}
 
start_color();			/* Start color 			*/
init_pair(1,COLOR_WHITE,COLOR_BLUE);
attron(COLOR_PAIR(1));
 
my_win = create_newwin(LINES, COLS/2, 0, 0);
 
print_position(my_win,1,1,"ONE");
attroff(COLOR_PAIR(1));
 
my_win = create_newwin(LINES, COLS/2, 0, COLS/2);
print_position(my_win,1,1,"TWO");
sleep(10);
destroy_win(my_win);
endwin();
return 0;
}
 
WINDOW *create_newwin(int height, int width, int starty, int startx)
{	WINDOW *local_win;
	local_win = newwin(height, width, starty, startx);
 
	box(local_win, 0 , 0);
	//init_pair(1,COLOR_WHITE,COLOR_BLUE);
	//init_color(COLOR_RED, 1000, 0, 0);
	//wattrset(stdscr,COLOR_PAIR(1));
	wrefresh(local_win);
	return local_win;
}
 
void destroy_win(WINDOW *local_win)
{	
	/* box(local_win, ' ', ' '); : This won't produce the desired
	 * result of erasing the window. It will leave it's four corners 
	 * and so an ugly remnant of window. 
	 */
	wborder(local_win, '+ ', '+ ', '+ ','+ ','+ ','+ ','+ ','+ ');
	/* The parameters taken are 
	 * 1. win: the window on which to operate
	 * 2. ls: character to be used for the left side of the window 
	 * 3. rs: character to be used for the right side of the window 
	 * 4. ts: character to be used for the top side of the window 
	 * 5. bs: character to be used for the bottom side of the window 
	 * 6. tl: character to be used for the top left corner of the window 
	 * 7. tr: character to be used for the top right corner of the window 
	 * 8. bl: character to be used for the bottom left corner of the window 
	 * 9. br: character to be used for the bottom right corner of the window
	 */
	wrefresh(local_win);
	delwin(local_win);
}
 
void print_position(WINDOW *local_win, int V, int H, std::string  my_string)
{
	if  (V == 0 and H == 0)
	{
		printw(my_string.c_str());
		refresh();
	}
	else
	{
		mvwprintw(local_win, V, H, my_string.c_str());
		wrefresh(local_win);
	}
} | 
Partager