荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: jjksam ([== 面壁大师 ==]), 信区: Linux
标  题: Re: 找不到graphics.h
发信站: 荔园晨风BBS站 (Tue Jul  2 14:17:05 2002), 转信

还有一个有颜色的:
/* File: helloworld.c */
#include <curses.h>

int main(int argc, char *argv[])
{
        int i;

        //initialize
        initscr();

        //initialize color
        if(!has_colors() || start_color() == ERR) {
                endwin();
                printf("Terminal does not support color.\n");
        }

        init_pair(1, COLOR_GREEN, COLOR_BLACK);
        init_pair(2, COLOR_RED, COLOR_BLACK);
        init_pair(3, COLOR_CYAN, COLOR_BLACK);
        init_pair(4, COLOR_WHITE, COLOR_BLACK);
        init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
        init_pair(6, COLOR_BLUE, COLOR_BLACK);
        init_pair(7, COLOR_YELLOW, COLOR_BLACK);


        for(i=1; i<=7; i++) {
                attron(COLOR_PAIR(i));
                printw("color pair %d in normal mode\n", i);
        }
        for(i=1; i<=7; i++) {
                attron(COLOR_PAIR(i) | A_BLINK | A_UNDERLINE);
                printw("color pair %d in normal mode\n", i);
        }

        //refresh screen
        refresh();

        //wait for input
        getch();

        //end
        endwin();
        exit(0);
}

【 在 jjksam ([== 面壁大师 ==]) 的大作中提到: 】
: 在Linux下面做图形化编程可以有很多选择.
: 可以利用ncurses函数库, curses是一个字符模式的与终端无关的高级函数库.它支持
: 颜色、窗口和一些高级组件。它可以工作在下列操作系统上: BeOS、CLIX、Cygwin、
: Digital UNIX、FreeBSD、GNU/Linux、IRIX、OS/2EMX、SCOOpenServer、Solaris、
: SunOS。

: 下面有一个helloworld的例子
: /* File: helloworld.c */
: /* compile with command: gcc -lcurses -o helloworld helloworld.c */
: #include <curses.h>
: int main(int argc, char *argv[])
: {
:         //initialize
:         initscr();
:         //draw border
:         box(stdscr, ACS_VLINE, ACS_HLINE);
:         //write string on line 11, row 30
:         mvaddstr(11, 30, "Hello World!");
:         //refresh screen
:         refresh();
:         //wait for input
:         getch();
:         //end
:         endwin();
:         exit(0);
: }
: 【 在 bigone ( happy birthday) 的大作中提到: 】
: :   那要在linux下面做初始化图形界面,该怎么做?


--
   mm       ★__      __  __ __★______ ______ __  __★
/^(  )^\      █      █  █/    █____ █__█ █∨█
\,(..),/  ▅__█  ▅__█  █\__  ▂__█ █  █ █  █
  V~~V   ▇▆▅▃▁I'm a bat. I'm very bad!^Q^_▃▄▆▇ 你好!^_^欢迎大家到linux

※ 修改:·jjksam 於 Jul  2 14:20:55 修改本文·[FROM: 192.168.0.146]
※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.0.146]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店