ncurses programming howto 书中源代码-6

/*
 * =====================================================================================
 *
 *       Filename:  p27_window.c
 *
 *    Description:  window_p27
 *
 *        Version:  1.0
 *        Created:  2010骞?9鏈?3鏃?21鏃?6鍒?8绉? *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:   cdutyangshaokun@163.com
 *        Company:  College of Information Engineering of CDUT
 *
 * =====================================================================================
 */
#include<ncurses.h>
WINDOW *creat_newwin(int height,int width,int starty,int startx);
void destroy_win(WINDOW *local_win);
int main(int argc,char *argv[])
{
    WINDOW *my_win;
    int startx,starty,width,height;
    int ch;
    initscr();
    cbreak();
    keypad(stdscr,TRUE);
    height=6;
    width=20;
    starty=(LINES-height)/2;
    startx=(COLS-width)/2;
    printw("press F2 to exit");
    refresh();
    my_win=creat_newwin(height,width,starty,startx);
    while((ch=getch())!=KEY_F(2))
    {
        switch(ch)
        {
            case KEY_LEFT:
                destroy_win(my_win);
                my_win=creat_newwin(height,width,starty,--startx);
                break;
            case KEY_RIGHT:
                destroy_win(my_win);
                my_win=creat_newwin(height,width,starty,++startx);
                break;
            case KEY_UP:
                destroy_win(my_win);
                my_win=creat_newwin(height,width,--starty,startx);
                break;
            case KEY_DOWN:
                destroy_win(my_win);
                my_win=creat_newwin(height,width,++starty,startx);
                break;
        }
    }
    endwin();
    return 0;
}

WINDOW *creat_newwin(int height,int width,int starty,int startx)
{
    WINDOW *local_win;
    local_win=newwin(height,width,starty,startx);
    box(local_win,0,0);
    wrefresh(local_win);
    return local_win;
}

void destroy_win(WINDOW *local_win)
{
    wborder(local_win,' ',' ',' ',' ',' ',' ',' ', ' ');
    wrefresh(local_win);
    delwin(local_win);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值