当前位置: 代码迷 >> C语言 >> TC图形编程驱动文件怎么装入程序
  详细解决方案

TC图形编程驱动文件怎么装入程序

热度:136   发布时间:2007-09-04 21:01:10.0
TC图形编程驱动文件怎么装入程序
运行TC 图形程序提示如下错误:


BGI ERROR :Graphics not initialized(use 'initgraph)  程序在调用initgraph()函数进行图形初始化时,没有将相应的动文件(*bgi)装入程序执行

  那么请问,怎么装入执行呢?
搜索更多相关的解决方案: 图形  文件  驱动  

----------------解决方案--------------------------------------------------------
建议你学习32位操作系统上的图形接口,而不是16位DOS



by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

[url=http://bbs.bc-cn.net/viewthread.php?tid=163571]请大家不要用TC来学习C语言,点击此处查看原因[/url]
C/C++算法习题(OnlineJudge):[url]http://yzfy.org/[/url]
----------------解决方案--------------------------------------------------------

我用的是win-tc 这个不行吗?有没有解决方法吗?


----------------解决方案--------------------------------------------------------

将bgi驱动注册到程序中的方法:
1、在bgi目录下找到bgiobj.exe这个程序,若你想把EGAVGA.bgi转换成EGAVGA.obj在命令行输入bgiobj EGAVGA
2、将生成egavga.obj添加到graphics.lib中,使用命令tlib graphic +egavga
(注:向graphics.lib添加字体也是同样方法,用bgiobj将字体文件*.chr转换成.obj)

上述两部完成以后可以写程序使用了:
/* 该程序摘自BC3.1的帮助手册 */
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;

/* register a driver that was added into graphics.lib */
/* For information on adding the driver, see the
/* BGIOBJ section of UTIL.DOC */
errorcode = registerbgidriver(EGAVGA_driver);

/* report any registration errors */
if (errorcode < 0)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}

/* draw a line */
line(0, 0, getmaxx(), getmaxy());

/* clean up */
getch();
closegraph();
return 0;
}
若对于注册图形驱动有问题,请查看util.doc文件,没有util.doc下载以下附件


----------------解决方案--------------------------------------------------------

奇怪了,,你的代码我复制了,可以运行,为什么我的就不行呢?你给看看吧:


#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>


int main(void)
{
/* 此处添加你自己的代码 */

int graphdriver=DETECT;
int graphmode,x,y;
detectgraph(&graphdriver,&graphmode);
initgraph(&graphdriver,&graphmode,"");
cleardevice();

for(y=20;y<200;y+=20)
{
for(x=20;x<=400;x+=12)
{
setcolor(GREEN);
line(x,y,x+4,y);
putpixel(x+8,y,YELLOW);
}
}

getch();
closegraph();
return 0;
}


----------------解决方案--------------------------------------------------------
  相关解决方案