一个简单的EGE程序:
#include "graphics.h" //EGE库的头文件 int main(int argc, char** argv) { initgraph(320,240); //初始化绘图窗口 outtextxy(20,120,"Aloha World!"); line(10,10,300,200); circle(30,40,20); ege::getch(); //此处加ege::名字空间,是因为conio.h文件里面也有getch函数。避免冲突被覆盖。 closegraph(); //绘图结束关闭绘图窗口。 return 0; //CPP程序不加最后的return也会返回一个整形。但是为了可读性,自己要加上。 }
下面看看“graphics.h”头文件里面的内容。(目录:C:\Program Files\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include --> graphics.h)
#ifndef _GRAPHICS_H_ #define _GRAPHICS_H_
/*声明必须用C++的编译器器才可以使用EGE图形库*/ #ifndef __cplusplus #error You must use C++ compiler, or you need filename with '.cpp' suffix #endif #include "ege.h" using namespace ege; #endif
一、inputbox_getline(); (具体参见EGE文档)
功能:
使用对话框让用户输入一个字符串。
inputbox_getline("这是一个对话框", "请随便\n输入一串字符,输入完请回车", str, sizeof(str)/sizeof(*str));
二、outtextxy ();
功能:
这个函数用于在指定位置输出字符串。 可以输出字符、字符串、数字值。
outtext();
功能:
这个函数用于在当前位置输出字符串。
三、getInteger(“TEXT");
功能:
显示对话框,让用户输入一个整数。text 对话框内显示的提示文字,可以使用'\n'或者'\t'进行格式控制。
四、getDouble("TEXT");
功能:
显示对话框,让用户输入一个双精度浮点数。text 对话框内显示的提示文字,可以使用'\n'或者'\t'进行格式控制。
五、getString();
功能:
显示对话框,让用户输入一个字符串,与inputbox_getline类似,但参数更少
getString(str, sizeof(str)/sizeof(*str), "请随便\n输入一串字符,输入完请回车");
getChar();
功能:
显示对话框,让用户输入一个字符。
六、getCoords();
功能:
显示对话框,让用户输入几组坐标。用户一次输入一组坐标,即两个坐标值,坐标值之间用逗号分隔,例如: 10,25
返回值:
返回指向coords数组的指针。
例: int coords[4];
int* PC = getCoords(coords, sizeof(coords)/sizeof(int)/2, "请输入坐标");
line(PC[0],PC[1], PC[2], PC[3]);
本节程序演示如下:
#include "graphics.h" int main() { initgraph(640,480); //用来接收输入 char s[100]; //调用对话框函数 inputbox_getline("(标题)请输入:","(提示)请输入一些字符串(回车确认)",s,100); //显示出入的内容 outtextxy(0,0,s); //调用输入一个整数函数 int x = getInteger("Please Input an Integer\n");//对话框内显示的提示文字,可以使用'\n'或者'\t'进行格式控制。 //显示 xyprintf(10,30,"This is an Integer : %d",x); //类似于printf //调用输入一个double型数据 double y = getDouble("Please Input a Double : \n"); xyprintf(10,60,"This is a Double: %lf",y); char str[100]; getString(str,100,"Please Input a String:\n:"); outtextxy(10,90,str); char c = getChar("Please Input a Char:"); outtext(c); //显示对话框,让用户输入指定数量的坐标,一次输入一对坐标,例如: 10,20 int coords[4]; int* PC = getCoords(coords,2,"Please Input a pare of Numbers:");//getCoords是一个返回coords点位指针的函数 line(PC[0],PC[1],PC[2],PC[3]); ege::getch(); closegraph(); return 0; }
( The End )
(Thank You !)