- 论坛徽章:
- 0
|
/*定义一些公共函数*/
/*2002-03-15*/
/*www.xiaoye.org*/
#include <stdio.h>;
#include <curses.h>;
/*清屏函数*/
void initial()
{
initscr();
cbreak();
nonl();
noecho();
intrflush(stdscr,FALSE);
keypad(stdscr,TRUE);
clear();
refresh();
}
/*退出窗口模式*/
int exitwin()
{
clear();
refresh();
endwin();
return 0;
}
/*返回主窗口函数*/
int backtomain(WINDOW *curwin) /*curwin 当前的窗口*/
{
clear();
box(stdscr, 0, 0);
touchwin(stdscr);
wrefresh(stdscr);
delwin(curwin);
refresh();
return 0;
}
/*提示信息在窗口某行居中*/
int FunCenterMsg(WINDOW *msgwin, char *msg, int wid, int y)
{
int msgx;
msgx = wid/2 - strlen(msg)/2 - 1;
mvwprintw(msgwin, y,msgx,"%s",msg);
wrefresh(msgwin);
return 0;
}
/*提示信息框函数*/
void msgbox(char *msg)
{
WINDOW *msgwin;
msgwin=newwin(3,30, LINES/2-3, COLS/2-15);
touchwin(msgwin);
wattrset(msgwin,A_REVERSE);
box(msgwin,0,0);
mvwprintw(msgwin,1,1," " ;
FunCenterMsg(msgwin,msg,30,1);
wrefresh(msgwin);
getch();
wclear(msgwin);
wattrset(msgwin,A_NORMAL);
box(stdscr, 0, 0);
touchwin(stdscr);
wrefresh(stdscr);
delwin(msgwin);
}
/*窗口添冲函数*/
int myfillwin(WINDOW *win, int lines, int cols)
{
int i;
for (i=0;i<lines;i++)
{
wmove(win,i,1);
whline(win,' ',cols);
}
box(win,0,0);
return 0;
}
/*主窗口的初始化*/
int FunDispBaseWin(char *title, char *foot)
{
box(stdscr,0,0);
wmove(stdscr,2, 1);
whline(stdscr,0,COLS - 2);
FunCenterMsg(stdscr, title, COLS, 1);
wmove(stdscr,LINES - 3, 1);
whline(stdscr,0,COLS - 2);
FunCenterMsg(stdscr, foot, COLS, LINES - 2);
wrefresh(stdscr);
return 0;
}
/*信息输入窗口*/
int FunInputBox(char *title,char *input)
{
WINDOW *inputwin;
memset(input,0,sizeof(input));
inputwin=newwin(4,30, LINES/2-4, COLS/2-15);
touchwin(inputwin);
wattrset(inputwin,A_REVERSE);
box(inputwin,0,0);
myfillwin(inputwin, 4, 30);
FunCenterMsg(inputwin,title,30,0);
wrefresh(inputwin);
//getch();
echo();
wattrset(inputwin,A_NORMAL);
wmove(inputwin,2,2);whline(inputwin,' ',30-4);
mvwscanw(inputwin,2,2,"%s",input);
noecho();
wclear(inputwin);
wattrset(inputwin,A_NORMAL);
box(stdscr, 0, 0);
touchwin(stdscr);
wrefresh(stdscr);
delwin(inputwin);
return 0;
}
/*主窗口中显示帮助信息*/
int FunShowTips(WINDOW *prewin, char *tips, int tipstype)
{
touchwin(stdscr);
wmove(stdscr,LINES-4,1);
whline(stdscr,' ',COLS-2);
mvwprintw(stdscr,LINES-4,2,"帮助: %s",tips);
wrefresh(stdscr);
if (tipstype==1) {getch();}
touchwin(prewin);
wrefresh(prewin);
return 0;
} |
|