概述
今天利用ncurses来创建了一个简单的窗口:
下面是源代码:
/*
* =====================================================================================
*
* Filename: p27_window.c
*
* Description: window_p27
*
* Version: 1.0
* Created: 2010年09月13日 21时06分18秒
* Revision: none
* Compiler: gcc
*
* Author: Yang Shao Kun (), 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);
}
效果图是这个样的:
可以移动上下左右键来控制:
最后
以上就是凶狠小懒虫为你收集整理的利用curses来创建窗口的全部内容,希望文章能够帮你解决利用curses来创建窗口所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复