⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 curlib.c

📁 用C语言实现的字符型的菜单界面
💻 C
📖 第 1 页 / 共 5 页
字号:
	wdraw_line(win,wrow-4,0,tcol+4,style);	wattroff(win,battr);	/* Display title */	if( *heading != 0 )	{		wattron(win,hattr);		tx = (wcol-tlen)/2;		if( (tx % 2) != 0 )			tx--;		else			tx-=2;		mvwaddstr(win,0,tx,heading);		wattroff(win,hattr);	}	if( (txtwin=subwin(win,trow,tcol,sy+1,sx+2)) == NULL )	{		return -1;	}	/* Display message text */	wcls(txtwin,tattr);	mvwaddstr(txtwin,0,0,msg);	touchwin(txtwin);	wrefresh(txtwin);	if( (newptr=(msgcmd_t *)malloc(sizeof(msgcmd_t))) == NULL )	{		return -1;	}	memset(newptr,'\0',sizeof(msgcmd_t));	headptr = newptr;	switch(flag)	{	case MSG_OC:		newptr->id = ID_OK;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[确认]");			newptr->coord = tcol/2-6;		}		else		{			strcpy(newptr->text,"[OK]");			newptr->coord = tcol/2-4;		}		if( (newptr=(msgcmd_t *)malloc(sizeof(msgcmd_t))) == NULL )		{			return -1;		}		memset(newptr,'\0',sizeof(msgcmd_t));		newptr->id = ID_CANCEL;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[取消]");			newptr->coord = tcol/2+2;		}		else		{			strcpy(newptr->text,"[CANCEL]");			newptr->coord = tcol/2+2;		}		newptr->next = headptr;		newptr->prev = headptr;		headptr->next = newptr;		headptr->prev = newptr;		item_num = 2;		break;	case MSG_YN:		newptr->id = ID_OK;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[是]");			newptr->coord = tcol/2-4;		}		else		{			strcpy(newptr->text,"[YES]");			newptr->coord = tcol/2-4;		}		if( (newptr=(msgcmd_t *)malloc(sizeof(msgcmd_t))) == NULL )		{			return -1;		}		memset(newptr,'\0',sizeof(msgcmd_t));		newptr->id = ID_CANCEL;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[否]");			newptr->coord = tcol/2+2;		}		else		{			strcpy(newptr->text,"[NO]");			newptr->coord = tcol/2+2;		}		newptr->next = headptr;		newptr->prev = headptr;		headptr->next = newptr;		headptr->prev = newptr;		item_num = 2;		break;	case MSG_RC:		newptr->id = ID_RETRY;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[重试]");			newptr->coord = tcol/2-6;		}		else		{			strcpy(newptr->text,"[RETRY]");			newptr->coord = tcol/2-4;		}		if( (newptr=(msgcmd_t *)malloc(sizeof(msgcmd_t))) == NULL )		{			return -1;		}		memset(newptr,'\0',sizeof(msgcmd_t));		newptr->id = ID_CANCEL;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[取消]");			newptr->coord = tcol/2+2;		}		else		{			strcpy(newptr->text,"[CANCEL]");			newptr->coord = tcol/2+2;		}		newptr->next = headptr;		newptr->prev = headptr;		headptr->next = newptr;		headptr->prev = newptr;		item_num = 2;		break;	case MSG_YNC:		newptr->id = ID_YES;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[是]");			newptr->coord = tcol/2-8;		}		else		{			strcpy(newptr->text,"[YES]");			newptr->coord = tcol/2-10;		}		ptr=newptr;		if( (newptr=(msgcmd_t *)malloc(sizeof(msgcmd_t))) == NULL )		{			return -1;		}		memset(newptr,'\0',sizeof(msgcmd_t));		newptr->id = ID_NO;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[否]");			newptr->coord = tcol/2-1;		}		else		{			strcpy(newptr->text,"[NO]");			newptr->coord = tcol/2-1;		}		ptr->next = newptr;		newptr->prev = ptr;		ptr=newptr;		if( (newptr=(msgcmd_t *)malloc(sizeof(msgcmd_t))) == NULL )		{			return -1;		}		memset(newptr,'\0',sizeof(msgcmd_t));		newptr->id = ID_CANCEL;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[取消]");			newptr->coord = tcol/2+6;		}		else		{			strcpy(newptr->text,"[CANCEL]");			newptr->coord = tcol/2+7;		}		ptr->next = newptr;		newptr->prev = ptr;		newptr->next = headptr;		headptr->prev = newptr;		item_num = 3;		break;	case MSG_ARI:		newptr->id = ID_ABORT;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[放弃]");			newptr->coord = tcol/2-11;		}		else		{			strcpy(newptr->text,"[ABORT]");			newptr->coord = tcol/2-11;		}		ptr=newptr;		if( (newptr=(msgcmd_t *)malloc(sizeof(msgcmd_t))) == NULL )		{			return -1;		}		memset(newptr,'\0',sizeof(msgcmd_t));		newptr->id = ID_RETRY;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[重试]");			newptr->coord = tcol/2-2;		}		else		{			strcpy(newptr->text,"[RETRY]");			newptr->coord = tcol/2-2;		}		ptr->next = newptr;		newptr->prev = ptr;		ptr=newptr;		if( (newptr=(msgcmd_t *)malloc(sizeof(msgcmd_t))) == NULL )		{			return -1;		}		memset(newptr,'\0',sizeof(msgcmd_t));		newptr->id = ID_IGNORE;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[忽略]");			newptr->coord = tcol/2+7;		}		else		{			strcpy(newptr->text,"[IGNORE]");			newptr->coord = tcol/2+7;		}		ptr->next = newptr;		newptr->prev = ptr;		newptr->next = headptr;		headptr->prev = newptr;		item_num = 3;		break;	case MSG_OK:		newptr->id = ID_OK;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[确认]");			newptr->coord = tcol/2-2;		}		else		{			strcpy(newptr->text,"[OK]");			newptr->coord = tcol/2;		}		newptr->next = newptr;		newptr->prev = newptr;		item_num = 1;		break;	case MSG_AK:	default:		newptr->id = ID_ANYKEY;		if( screen.wstyle & WINDOW_CHINESE )		{			strcpy(newptr->text,"[按任意键]");			newptr->coord = tcol/2-4;		}		else		{			strcpy(newptr->text,"[ANY KEY]");			newptr->coord = tcol/2-4;		}		newptr->next = newptr;		newptr->prev = newptr;		item_num = 1;		break;	}	/* Display item */	wcls_line(win,trow+2,2,tcol,battr);	ptr=headptr;	do {		mvwaddstr(win,trow+2,ptr->coord,ptr->text);		ptr=ptr->next;	} while( ptr != headptr);	touchwin(win);	wrefresh(win);	ptr=headptr;	if( (flag == MSG_AK) || (flag == 0) || (item_num == 1) )	{		wattron(win,sattr);			mvwaddstr(win,trow+2,ptr->coord,ptr->text);		wattroff(win,sattr);			wrefresh(win);		get_char();		ret = ptr->id;	}	else	{		loop=TRUE;		while(loop)		{			wattron(win,sattr);				mvwaddstr(win,trow+2,ptr->coord,ptr->text);			wattroff(win,sattr);				wrefresh(win);			switch(get_funckey(&ch))			{			case KeyEnter:				ret=ptr->id;				loop=FALSE;				break;			case KeyDown:			case KeyRight:				wattron(win,tattr);					mvwaddstr(win,trow+2,ptr->coord,ptr->text);				wattroff(win,tattr);					wrefresh(win);				ptr=ptr->next;				break;			case KeyUp:			case KeyLeft:				wattron(win,tattr);					mvwaddstr(win,trow+2,ptr->coord,ptr->text);				wattroff(win,tattr);					wrefresh(win);				ptr=ptr->prev;				break;			default:;			} /* end of switch */		} /* end of while */	}	delwin(txtwin);	delwin(win);	touchwin(stdscr);	wrefresh(stdscr);	if( headptr->next != NULL )		free(headptr->next);	if( headptr->prev != NULL )		free(headptr->next);	if( headptr != NULL )		free(headptr);	return ret;}/*----------------------------------------------------------------------------* * Function: 在窗口中画一条制表线. * Argument: *           WINDOW *win - 窗口. *           short sy - 开始行. *           short sx - 开始列. *           int width - 宽度. *           chtype style - 窗口风格: WINDOW_SHADE, WINDOW_CHINESE. * Return  :  *           TRUE. *----------------------------------------------------------------------------*/draw_line(int sy,int sx,int width){	attron(screen.board);	wdraw_line(stdscr,sy,sx,width,screen.wstyle);	attron(screen.board);}/*----------------------------------------------------------------------------* * Function: 在窗口中画一条制表线. * Argument: *           WINDOW *win - 窗口. *           short sy - 开始行. *           short sx - 开始列. *           int width - 宽度. *           chtype style - 窗口风格: WINDOW_SHADE, WINDOW_CHINESE. * Return  :  *           TRUE. *----------------------------------------------------------------------------*/wdraw_line(WINDOW *win,int sy,int sx,int width,chtype flag){	short i;	if( flag & WINDOW_SHADE )	{		if( flag & WINDOW_ENGLISH )		{			mvwaddch(win,sy,sx,0xc3);			for(i=1;i<width-2;i++)				mvwaddch(win,sy,sx+i,0xc4);			mvwaddch(win,sy,sx+width-2,0xb4);		}		else		{			mvwaddstr(win,sy,sx,"├");			for(i=2;i<width-4;i+=2)				mvwaddstr(win,sy,sx+i,"─");			mvwaddstr(win,sy,sx+width-4,"┤");		}	}	else	{		if( flag & WINDOW_ENGLISH )		{			mvwaddch(win,sy,sx,0xc3);			for(i=1;i<width-1;i++)				mvwaddch(win,sy,sx+i,0xc4);			mvwaddch(win,sy,sx+width-1,0xb4);		}		else		{			mvwaddstr(win,sy,sx,"├");			for(i=2;i<width-2;i+=2)				mvwaddstr(win,sy,sx+i,"─");			mvwaddstr(win,sy,sx+width-2,"┤");		}	}	wrefresh(win);}/******************************************************************************  * <第二章> 输入函数.                                                         * ******************************************************************************//*----------------------------------------------------------------------------* * FUNCTION: Get a Char from keybord. No wait. * Argument: *           None. * Return  :  *           > 0 - If You Press Key. *           = 0 - If no key pressed. * * Notes   : If You Press Cursor_Key,You Must Call get_key() 3 Times. *----------------------------------------------------------------------------*/get_key(){	unsigned char c;	if( read(0,&c, 1) != 0 )		return c;	else		return 0;}/*----------------------------------------------------------------------------* * FUNCTION: Get Char From Keyboard. Wait. * Argument: *           None. * Return  :  *           > 0 - If You Press Key. * * Notes   : If No Key Press, Wait Until Key Pressed. *----------------------------------------------------------------------------*/get_char(){	unsigned char c;	while (!(c=get_key()));	return c;}/*----------------------------------------------------------------------------* * Function: Get function key from Keyboard, Wait. * Argument: *           unsigned char *c - Get char. * Return  :  *           0 - if you press other Key,and 'c' is the key by pressed. *           Funckey - if you press special key,and c=0.  *----------------------------------------------------------------------------*/get_funckey(unsigned char *c){	unsigned char ch;	ch=get_char();	switch(ch)	{	case KeyEnter:	case KeyTab:	case KeyBkSpace:		*c =0;		return ch;		break;	case KeyEsc:		ch=get_key();		if(ch ==0) /* Press ESC */		{			*c=0;			return KeyEsc;		}		else /* Other function key */		{			ch=get_key();			*c=0;			return ch;		}		break;	default:		*c=ch;		return 0;		break;	}}/*----------------------------------------------------------------------------* * FUNCTION: 从(y,x)处得到一个字符并显示. * Argument: *           int y - 开始行. *           int x - 开始列. * Return  :  *           输入字符. * 说    明: *----------------------------------------------------------------------------*/mvget_char(int y,int x){	unsigned char ch;	if( need_check_flag == 1 )	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -