免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2633 | 回复: 1
打印 上一主题 下一主题

[函数] 一些关于UNIX下窗口编程的公共函数,很好用的噢! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-06-10 13:47 |只看该作者 |倒序浏览
/*定义一些公共函数*/
/*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;
}

论坛徽章:
0
2 [报告]
发表于 2003-06-10 13:58 |只看该作者

一些关于UNIX下窗口编程的公共函数,很好用的噢!

可以发ncurses入门教程了


每一方面都写到了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP