程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C指針原理(66)-Ncurses-文本終端的圖形

C指針原理(66)-Ncurses-文本終端的圖形

編輯:關於C語言

下面將全屏編輯器修改一下,通過panel的支持,讓它能同時打開3個窗口編輯不同的內容,同時對3個窗口的內容進行保存。

效果如下:

\

<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPGgxPsLzusO1xEFJwNbUsLKpv83L+dPQxNrI3crH1K20tKOsyOe5+9eq1NjH69eiw/fAtNS0PC9oMT4KPGgzPgpodHRwOi8vYmxvZy5jc2RuLm5ldC9teWhhc3BsLzwvaDM+Cjxicj4KPHA+PC9wPgo8cD4jaW5jbHVkZSA8bG9jYWxlLmg+PC9wPgo8cD4jaW5jbHVkZSA8c3RkaW8uaD48L3A+CjxwPiNpbmNsdWRlIDxwYW5lbC5oPjwvcD4KPHA+I2luY2x1ZGUgPG5jdXJzZXMuaD48L3A+CjxwPi8vY29kZSBieSBteWhhc3BsQG15aGFzcGwuY29tPC9wPgo8cD4vL2RhdGU6MjAxNC8xLzE3PC9wPgo8cD5pbnQgaXNFeGlzdChjaGFyICpmaWxlbmFtZSk8L3A+CjxwPns8L3A+CjxwPiAgICAgICAgIHJldHVybiAoYWNjZXNzKGZpbGVuYW1lLCAwKSA9PSAwKTs8L3A+CjxwPn08L3A+CjxwPmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pPC9wPgo8cD57PC9wPgo8cD4gICAgICAgIE1FVkVOVCBldmVudDs8L3A+CjxwPiAgICAgICAgc2V0bG9jYWxlKExDX0FMTCw="");

initscr();

clear();

noecho();

cbreak();

if(has_colors() == FALSE)

{

endwin();

printf("你的終端不支持色彩!\n");

return (1);

}

start_color(); /*啟動color 機制*/

mvprintw(3,COLS/2-10,"簡單編輯器-僅限於單個屏幕的編輯");

mvprintw(4,COLS/2-20,"【F9讀保存內容,F10存盤,F11退出,F12刪除整行,TAB換窗口】");

refresh();

init_pair(1, COLOR_GREEN, COLOR_BLACK);

init_pair(2, COLOR_BLUE, COLOR_BLACK);

init_pair(3, COLOR_RED,COLOR_BLACK);

WINDOW *mywins[3];

PANEL *top;

PANEL *mypanels[3];

char filename[10];

int width=COLS-18;

int height=LINES-18;

int x,y;

int begin_y=5;int begin_x=5;

int i;

for(i = 0; i < 3; +++i)

{

mywins[i]=newwin(height,width,begin_y,begin_x);//新窗口(行,列,begin_y,begin_x)

keypad(mywins[i],TRUE);

wattron(mywins[i],COLOR_PAIR(i+1));

mypanels[i] = new_panel(mywins[i]);

box(mywins[i],ACS_VLINE,ACS_HLINE);

wattroff(mywins[i],COLOR_PAIR(i+1));

begin_y+=4;begin_x+=4;

}

set_panel_userptr(mypanels[0],mypanels[1]);

set_panel_userptr(mypanels[1],mypanels[2]);

set_panel_userptr(mypanels[2],mypanels[0]);

top = mypanels[2];

update_panels();

doupdate();

int nowwinid=2;

sprintf(filename,"myed%d.dat",nowwinid);

getyx(mywins[nowwinid],y,x);

++y;++x;

mmask_t oldmousemask;

int ans=0;

FILE *fp2=NULL;

FILE *fp1=NULL;

mousemask(ALL_MOUSE_EVENTS, &oldmousemask);

while(1){

int c=mvwgetch(mywins[nowwinid],y,x);

switch(c)

{ case KEY_MOUSE:

if(getmouse(&event) == OK)

{ /* When the user clicks left mouse button */

if(event.bstate & BUTTON1_PRESSED)

{

y=event.y-7;x=event.x-7;

wmove(mywins[nowwinid],y,x);

}

}

break;

case KEY_BACKSPACE:

--x;

if (x<1){

--y;x=width-2;

}

if (y<1){

y=height-2;

}

mvwprintw(mywins[nowwinid],y,x," ");

break;

case KEY_RIGHT:

++x;

if (x>=width-1) {

++y;

x=1;

}

break;

case KEY_LEFT: --x;

if (x<1){

--y;

x=width-2;

}

break;

case KEY_UP:

--y;

if (y<1){

y=height-2;

}

break;

case KEY_DOWN:

++y;

if (y>=height-1){

y=1;

}

break;

case 10:

++y;

if (y>=height-1){

y=1;

}

break;

case KEY_F(11):

//退出

mvprintw(LINES-3,2," ");

mvprintw(LINES-3,2,"退出編輯器嗎? ");

mvprintw(LINES-2,2," ");

mvprintw(LINES-1,2," \n");

refresh();

ans=getch();

if (ans=='Y' ||ans=='y')

{

mvprintw(LINES-2,2,"是\n");

refresh();

wattroff(mywins[nowwinid],COLOR_PAIR(1));

mousemask(oldmousemask,NULL);

endwin();

return 0;

}else

mvprintw(LINES-2,2,"否\n");

refresh();

break;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved