4、對中文的支持
dp@dp:~/cursestest % cat 1.c
#include
#include
#include
int main(void){
//init_pair(short index,short foreground,short background)初始化顏色索引
//attron(COLOR_PAIR(索引號)|屬性)
setlocale(LC_ALL,"");
initscr();//初始化
box(stdscr,ACS_VLINE,ACS_HLINE);//畫邊框
if (!has_colors()||start_color()==ERR){
endwin();
printf("終端不支持顏色\n");
return 0;
}
init_pair(1,COLOR_GREEN,COLOR_BLACK);
init_pair(2,COLOR_RED,COLOR_BLACK);
init_pair(3,COLOR_WHITE,COLOR_BLUE);
int i=0;
for (i=1;i<=3;i++){
attron(COLOR_PAIR(i));
move(i,10);
printw("hello,世界%d",i);
}
for (i=1;i<=3;i++){
attron(COLOR_PAIR(i)|A_UNDERLINE);
move(i+5,10);
printw("hello,世界:%d",i);
}
refresh();//刷新屏幕
getch();//等待按鍵
endwin();//結束
return 0;
}
麥好的AI樂園博客所有內容是原創,如果轉載請注明來源
http://blog.csdn.net/myhaspl/
編譯時注意要使用ncursesw庫,不使用ncurses庫
dp@dp:~/cursestest % gcc -lncursesw 1.c -o mytest
dp@dp:~/cursestest % ./mytest
運行效果 :

5、窗口與子窗口<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHByZSBjbGFzcz0="brush:java;">dp@dp:~/cursestest % cat 1.c
#include
#include
int main(){
//init_pair(short index,short foreground,short background)初始化顏色索引
//attron(COLOR_PAIR(索引號)|屬性)
//newwin建立窗口,derwin建立窗口的子窗口(相對於父窗口相對位置),subwin建立窗口的子窗口(相對於根窗口絕對位置)
setlocale(LC_ALL,"");
WINDOW *win1,*win2,*subwin;
initscr();//初始化
win1=newwin(15,50,1,1);//新窗口(行,列,begin_y,begin_x)
box(win1,ACS_VLINE,ACS_HLINE);
mvwprintw(win1,1,1,"WIN1");
mvwprintw(win1,2,1,"您好,很高興認識您");
win2=newwin(10,40,10,30);//新窗口(行,列,begin_y,begin_x)
box(win2,ACS_VLINE,ACS_HLINE);
mvwprintw(win2,1,1,"WIN2");
mvwprintw(win2,2,1,"您好,很高興認識您");
subwin=derwin(win2,3,20,3,5); //子窗口
box(subwin,ACS_VLINE,ACS_HLINE);
mvwprintw(subwin,1,5,"按任意鍵退出");//(窗口,y,x,字符串)
refresh();//刷新整個大窗口stdscr
wrefresh(win1);
wrefresh(win2);
touchwin(win1);//轉換當前窗口為win1
wrefresh(win1);
getch();//win1顯示完,等待按鍵顯示win2
touchwin(win2);//轉換當前窗口為win2
//使用doupdate,可以事先定義要刷新的部分,然後刷新
wnoutrefresh(win2);
wnoutrefresh(subwin);
doupdate();
getch();//等待按鍵
delwin(win1);
delwin(subwin);
delwin(win2);
endwin();//結束
return 0;
}
dp@dp:~/cursestest % gcc -lncursesw 1.c -o mytest
dp@dp:~/cursestest % ./mytest
