6、自動滾屏
dp@dp:~/cursestest % cat 2.c
#include
#include
int main(void){
int y,x,i,j,h,w;
setlocale(LC_ALL,"");
WINDOW *pad;
initscr();//初始化
getmaxyx(stdscr,h,w);//獲得屏幕尺寸
//畫背景
for(i=0;i for(j=0;j mvaddch(i,j,ACS_CKBOARD); } } refresh(); //建立窗口 pad=newpad(80,90); for (i=0;i<80;i++){ char line[90]; sprintf(line,"line %d\n",i); mvwprintw(pad,i,1,line); } refresh(); prefresh(pad,0,1,5,10,20,25);//刷新pad。0,1 為基墊需要顯示區域的左上角置(行列對,以下同此)。5,10,20,45為屏幕顯示區域的左上角和右下角位置 for(i=0;i<65;i++){ prefresh(pad,i+1,1,5,10,20,25);//刷新pad,實現流屏; usleep(30000); } getch();//等待按鍵 delwin(pad); endwin();//結束 return 0; } dp@dp:~/cursestest % gcc -lncursesw 2.c -o mytest dp@dp:~/cursestest % ./mytest seo8L3A+CjxwPmRwQGRwOn4vY3Vyc2VzdGVzdCAlIGNhdCAyLmM8L3A+CjxwPiNpbmNsdWRlIDxuY3Vyc2VzLmg+IDwvcD4KPHA+I2luY2x1ZGUgPGxvY2FsZS5oPiA8L3A+CjxwPiA8L3A+CjxwPmludCBtYWluKHZvaWQpeyA8L3A+CjxwPiA8L3A+CjxwPi8vaW5pdF9wYWlyKHNob3J0IGluZGV4LHNob3J0IGZvcmVncm91bmQsc2hvcnQgYmFja2dyb3VuZCmz9cq8u6/R1cmry/fS/SA8L3A+CjxwPiA8L3A+CjxwPi8vYXR0cm9uKENPTE9SX1BBSVIoy/fS/brFKQ=="屬性) //newwin建立窗口,derwin建立窗口的子窗口(相對於父窗口相對位置),subwin建立窗的子窗口(相對於根窗口絕對位置) int x,y; 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,"[email protected]"); win2=newwin(10,40,10,30);//新窗口(行,列,begin_y,begin_x) box(win2,ACS_VLINE,ACS_HLINE); wmove(win2,1,1);//移動某窗口的光標 printw("WIN2"); wmove(win2,2,1);//移動某窗口的光標。(窗口,y,x) printw("[email protected]"); subwin=derwin(win2,3,20,4,5); //子窗口 box(subwin,ACS_VLINE,ACS_HLINE); mvwprintw(subwin,1,5,"按任意鍵退出");//(窗口,y,x,字符串) refresh();//刷新整個大窗口stdscr wrefresh(win1); wrefresh(win2); move(5,60);//在stdscr移動光標 printw("hello........."); touchwin(win1);//轉換當前窗口為win1 wrefresh(win1); getch();//win1顯示完,等待按鍵顯示win2 touchwin(win2);//轉換當前窗口為win2 //使用doupdate,可以事先定義要刷新的部分,然後刷新 wnoutrefresh(win2); wnoutrefresh(subwin); doupdate(); getyx(subwin,y,x);//獲得當前邏輯光標位置 mvwprintw(subwin,y+1,x,"................");//在“按任意鍵退出"下一行輸出"..............." getch();//等待按鍵 delwin(win1); delwin(subwin); delwin(win2); endwin();//結束 return 0; } 編譯後運行 dp@dp:~/cursestest % gcc -lncursesw 2.c -o mytest dp@dp:~/cursestest % ./mytest 8、菜單 dp@dp:~/cursestest % cat 2.c #include #include #include #include //定義菜單項 static const char *menus[]={ "1-1","1-2","1-3","2-1","2-2","2-3" }; #define CITEM sizeof(menus)/sizeof(menus[0])//菜單項數 ITEM *items[CITEM]; int main(int argc,char *argv[]){ int i; int ch; int mrows,mcols; WINDOW *win,*subwin; MENU *mymenu; //初始化屏幕 initscr(); //不用等待回車鍵 cbreak(); //不回顯 noecho(); //可以處理功能鍵 keypad(stdscr,TRUE); //建立菜單項 for(i=0;i items[i]=new_item(menus[i],menus[i]);//第二個參數為菜單項的描述 } //建立菜單 mymenu=new_menu(items); set_menu_format(mymenu,CITEM,1); //設置CITEM行1列的菜單 set_menu_mark(mymenu,">");//菜單選中的MARK //獲得菜單的行列數 scale_menu(mymenu,&mrows,&mcols); //建立窗口和子窗口 win=newwin(mrows+2,mcols+2,3,30); keypad(win,TRUE); box(win,0,0); subwin=derwin(win,0,0,1,1); //設置菜單的窗口 set_menu_sub(mymenu,subwin); //在子窗口上放置菜單 post_menu(mymenu); refresh(); wrefresh(win); //獲得輸入,並移動選擇到相應的菜單項 while(toupper(ch=wgetch(win))!='\n'){ if(ch==KEY_DOWN) menu_driver(mymenu,REQ_DOWN_ITEM);//移動菜單選擇 else if(ch==KEY_RIGHT) menu_driver(mymenu,REQ_RIGHT_ITEM); else if (ch==KEY_UP) menu_driver(mymenu,REQ_UP_ITEM); else if (ch==KEY_LEFT) menu_driver(mymenu,REQ_LEFT_ITEM); } //輸出當前項 mvprintw(LINES-2,0,"you select the item :%s\n",item_name(current_item(mymenu))); refresh(); unpost_menu(mymenu); getch(); //釋放內存 free_menu(mymenu); for(i=0;i endwin(); return 1; } 編譯並運行 dp@dp:~/cursestest % gcc -lncursesw -lmenu 2.c -o mytest dp@dp:~/cursestest % ./mytest麥好的AI樂園博客所有內容是原創,如果轉載請注明來源
http://blog.csdn.net/myhaspl/
麥好的AI樂園博客所有內容是原創,如果轉載請注明來源
http://blog.csdn.net/myhaspl/