当前位置:早雪网网络学院编程文档C/C++ → 在Unix下用C编写类Windows菜单

在Unix下用C编写类Windows菜单

减小字体 增大字体 作者:不详  来源:supcode.com收集整理  发布时间:2005-7-22 19:39:06
spnextline("R");  
}  
else  
curpos++;  
if ((curpos%m_conf.m_col == 0) && (m_conf.m_lengh == 1)) {  
revcurpos(); break;  
}  
else {  
nomlastpos(); revcurpos();  
}  
}  
break;  
case KEY_LEFT: /* 左光标键 */  
if ( scrpos->prev != NULL ) {  
lastcurpos = curpos; lastscrpos = scrpos;  
scrpos=scrpos->prev;  
getyx(curw, x, y);  
if ((x==0) && (curpos%m_conf.m_col ==0)) {  
curpos+=m_conf.m_col-1; lastcurpos = curpos + 1;  
/* 实现向下卷屏 */  
winsertln(curw); dispprevline("L");  
}  
else  
curpos--;  
if ((curpos%m_conf.m_col==m_conf.m_col-1)&&(m_conf.m_lengh==1)) {  
revcurpos(); break;  
}  
else {  
nomlastpos(); revcurpos();  
}  
}  
break;  
case KEY_UP: /* 上光标键 */  
lastcurpos = curpos; lastscrpos = scrpos;  
mpos = scrpos;  
for(i=0; i/td>  
if ( mpos->prev != NULL ) mpos=mpos->prev;  
else break;  
}  
if ( i==m_conf.m_col ) {  
getyx(curw, x, y);  
if (x==0) {  
lastcurpos += m_conf.m_col;  
/* 实现向下卷屏 */  
winsertln(curw); dispprevline("U");  
}  
else {  
curpos-=m_conf.m_col;  
}  
scrpos = mpos;  
if ( m_conf.m_lengh!=1)  
nomlastpos();  
revcurpos();  
}  
break;  
case KEY_DOWN: /* 下光标键 */  
lastcurpos = curpos; lastscrpos = scrpos;  
mpos = scrpos;  
for(i=0; i/td>  
if ( mpos->next != NULL )  
mpos=mpos->next;  
else  
break;  
}  
if ( i==m_conf.m_col ) {  
getyx(curw, x, y);  
if (x==m_conf.m_lengh-1) {  
lastcurpos -= m_conf.m_col;  
/* 实现向上卷屏 */  
wmove(curw, 0, 0); wdeleteln(curw); dispnextline("D");  
}  
else  
curpos+=m_conf.m_col;  
scrpos = mpos;  
if ( m_conf.m_lengh!=1)  
nomlastpos();  
revcurpos();  
}  
break;  
default:  
beep();  
break;  
}  
}  
}  
/* 反显当前项函数 */  
void revcurpos()  
{  
wattrset(curw, A_STANDOUT);  
wmove(curw, curpos/m_conf.m_col,  
(curpos%m_conf.m_col)*m_conf.m_wight/m_conf.m_col+m_conf.m_col);  
wprintw(curw, "%s", scrpos->item);  
wattrset(curw, A_NORMAL);  
wrefresh(boxwin);  
}  
/* 正常显示上一项函数 */  
void nomlastpos() {  
wmove(curw, lastcurpos/m_conf.m_col, (lastcurpos%m_conf.m_col)  
*m_conf.m_wight/m_conf.m_col+m_conf.m_col);  
wprintw(curw, "%s", lastscrpos->item);  
}  
/* 显示一页函数 */  
void disponepage(first)  
struct menu *first;  
{  
short col, row;  
 
begin=first; /* begin 为本页首指针 */  
for(row=0; row/td>  
for(col=0; col/td>  
/* m_conf.m_wight/m_col为每一菜单项应占列数*/  
wmove(curw,row,col*m_conf.m_wight/m_conf.m_col+m_conf.m_col);  
wprintw(curw, "%s", first->item);  
wrefresh(curw);  
last = first;  
first = first->next;  
if (first == NULL) {  
break;  
}  
}  
}  
}  
/* 显示上一行函数 */  
void dispprevline(flag)  
char flag[2]; /* L-左光标引起 U-上光标引起 */  
{  
struct menu *tmppos;  
int tmpcurpos;  
 
tmpcurpos = curpos;  
tmppos = scrpos;  
if ( flag[0] == 'U') {  
while ( tmpcurpos % m_conf.m_col != 0) {  
tmppos = tmppos->prev;  
tmpcurpos--;  
}  
tmppos = tmppos->prev;  
}  
for (tmpcurpos = m_conf.m_col-1; tmpcurpos >= 0; tmpcurpos--) {  
wmove(curw, 0, (tmpcurpos%m_conf.m_col)  
*m_conf.m_wight/m_conf.m_col+m_conf.m_col);  
wprintw(curw, "%s", tmppos->item);  
begin = tmppos; /*begin 为本页首指针*/  
last = tmppos;  
tmppos = tmppos->prev;  
if (tmppos == NULL)  
break;  
}  
wrefresh(curw);  
}  
/* 显示下一行函数 */  
void dispnextline(flag)  
char flag[2];/* R-右光标引起 D-下光标引起 */  
{  
struct menu *tmppos;  
int tmpcurpos;  
 
tmpcurpos = curpos;  
tmppos = scrpos;  
if ( flag[0] == 'D') {  
while ( tmpcurpos % m_conf.m_col != m_conf.m_col-1) {  
tmppos = tmppos->next; tmpcurpos++;  
}  
tmppos = tmppos->next;  
}  
 
for (tmpcurpos = 0; tmpcurpos < m_conf.m_col; tmpcurpos++) {  
wmove(curw, m_conf.m_lengh-1, (tmpcurpos%m_conf.m_col)  
*m_conf.m_wight/m_conf.m_col+m_conf.m_col);  
wprintw(curw, "%s", tmppos->item);  
last=tmppos;/* last 为本页最后一个结点指针 */  
begin=tmppos; tmppos = tmppos->next;  
if (tmppos == NULL)  
break;  
}  
}  
/* 取指定菜单参数函数 */  
void getmenuconf(menu_code)  
short menu_code;  
{  
FILE *fp;  
char menu_buff[0x100];  
 
if ((fp = fopen("menu.conf", "r"))==NULL) {  
fprintf(stderr, "can not open menu config file");  
return;  
}  
while( fgets(menu_buff, 0x100, fp)!=NULL ) {  
get_m_conf(menu_buff);  
if (m_conf.menu_code == menu_code)  
break;  
}  
return ;  
}  
/* 取指定菜单参数处理函数 */  
void get_m_conf(menu_conf)  
char *menu_conf;  
{  
register i, j, k;  
char buff[20];  
 
j = k = 0;  
for (i = 0; i < strlen(menu_conf); i++) {  
if ( menu_conf[i] == '!' ) {  
j++;  
if ( j == 1) {  
k = i+1;  
continue;  
}  
switch(j) {  
case 2:  
memcpy(buff, &menu_conf[k], i-k);  
buff[i-k]=0;  
m_conf.menu_code = atoi(buff);  
k=i+1;  
break;  
case 3:  
memcpy(buff, &menu_conf[k], i-k);  
buff[i-k]=0;  
m_conf.last_code = atoi(buff);  
k=i+1;  
break;  
case 4:  
memcpy(buff, &menu_conf[k], i-k);  
buff[i-k]=0;  
m_conf.bord_flag = atoi(buff);  
k=i+1;  
break;  
case 5:  
memcpy(buff, &menu_conf[k], i-k);  
buff[i-k]=0;  
m_conf.m_wight = atoi(buff);  
k=i+1;  
break;  
case 6:  
memcpy(buff, &menu_conf[k], i-k);  
buff[i-k]=0;  
m_conf.m_lengh = atoi(buff);  
k=i+1;  
break;  
case 7:  
memcpy(buff, &menu_conf[k], i-k);  
buff[i-k]=0;  
m_conf.m_col = atoi(buff);  
k=i+1;  
break;  
case 8:  
memcpy(buff, &menu_conf[k], i-k);  
buff[i-k]=0;  
m_conf.m_bx = atoi(buff);  
k=i+1;  
break;  
case 9:  
memcpy(buff, &menu_conf[k], i-k);  
buff[i-k]=0;  
m_conf.m_by = atoi(buff);  
k=i+1;  
break;  
default:  
break;  
}  
}  
}  
}  
/* 取指定项参数处理函数 */  
void get_m_item(menu_item)  
char *menu_item;  
{  
register i, j, k;  
char buff[80];  
 
j = k = 0;  
for (i = 0; i < strlen(menu_item); i++) {  
if ( menu_item[i] == '!' ) {  
j++;  
if ( j == 1) {  
k = i+1;  
continue;  
}  
switch(j) {  
case 2:  
memcpy(buff, &menu_item[k], i-k);  
buff[i-k] = 0;  
m_item.menu_code = atoi(buff);  
k=i+1;  
break;  
case 3:  
memcpy(buff, &menu_item[k], i-k);  
buff[i-k] = 0;  
m_item.item_order = atoi(buff);  
k=i+1;  
break;  
case 4:  
memcpy(buff, &menu_item[k], i-k);  
buff[i-k] = 0;  
strcpy(m_item.item,buff);  
k=i+1;  
break;  
case 5

上一页  [1] [2] [3]  下一页

[数据载入中...] [返回上一页] [打 印]