Software 版 (精华区)

发信人: checcy (老巴夺), 信区: Software
标  题: 让C/C++图形程序独立运行
发信站: 哈工大紫丁香 (Mon Apr  6 11:43:04 1998), 转信

让C/C++图形程序独立运行


                         大家知道,C/C++语言提供了十分丰富的图形
                  函数,图形函数文件为 Graphicsh,使用图形函数前须
                  先将屏幕设置为图形模式, C/C++语言提供了下面的函
               数:                                              

                      void far initgraph(int far *GD,int far *
                GM,char *P);                                    

                        其中,GD和GM分别表示图形驱动程序和图形模式
                 , P指图形驱动程序所在的目录路径。                

                       图形驱动程序由Borland公司(对于Turbo C和Bor
                  land C++)提供,同时C/C++语言还提供了退出图形状
                态的函数closegraph(),格式为:                    

                     void far closegraph(void);                

                         也许你经常在用C/C++语言编写一些图形程序
                  ,但是总不能脱离 C/C++语言环境独立运行,我们怎样
                来解决呢 ?                                        

                        能否建立一个不需要驱动程序和字体文件也能独
                   立运行的图形程序呢 ?笔者经过实践,得到了肯定的答案
                  ,下面是实现图形程序独立运行的具体步骤:          

                       1将驱动程序EGAVGABGI转换成目标文件EGAV
                GAOBJ:                                        

                      D:\BC\BGI>BGIOBJ EGAVGA                  

                         按同样的办法,将字体文件*CHR转换成目标
                文件* OBJ:                                    

                      D:\BC\BGI>BGIOBJ TRIP                    

                      D:\BC\BGI>BGIOBJ LITT                    

                      D:\BC\BGI>BGIOBJ SANS                    

                      D:\BC\BGI>BGIOBJ GOTH                    

                        2将上述建立的OBJ文件加入到GRAPHICSLIB
                 库文件中,具体方法如下:                          

                      D:\BC\BGI>TLINK D:\BC\LIB\GRAPHICSLIB+E
                GAVGA                                            

                      D:\BC\BGI>TLINK D:\BC\LIB\GRAPHICSLIB+T
                RIP                                              

                      D:\BC\BGI>TLINK D:\BC\LIB\GRAPHICSLIB+L
                ITT                                              

                      D:\BC\BGI>TLINK D:\BC\LIB\GRAPHICSLIB+S
                ANS                                              

                      D:\BC\BGI>TLINK D:\BC\LIB\GRAPHICSLIB+G
                OTH                                              

                       也可以使用TLIB、PRJ程序代替TLINK。        

                        3在程序中调用initgraph()函数前,应加上如
                下语句:                                          

                       registerbgidriver(EGAVGA-driver);      

                        它通知连接程序把EGAVGA驱动程序装入用户的执
                   行程序中,同样在装入字体文件之前要加上如下语句:  

                       registerbgifont(字体文件名);            

                         4通过上述处理后,编译连接后的执行程序就
                   可以在任何目录下运行了。这时,将屏幕初始化为图形模
                式的函数可改写为:                                

                     void InitGra(void)                        

                     {int GD=DETECT,GM;                        

                       registerbgidriver(EGAVGA_ driver);      

                      registerbgifont(triplex_ font);          

                      registerbgifont(small_ font);            

                      registerbgifont(sansserif_ font);        

                     registerbgifont(gothic_ font);            

                      initgraph(&GD,&GM,″″);                

                      }                                        

                        按照以上步骤,就能实现图形程序的独立运行,
                 笔者在 Turbo C20、Borland C++20、Borland C+
                +31下均运行通过。                              

                      (贵州  邱自成)                          

-- 
*********************************
Chengyan Che - Software Freelancer
Harbin, P.R.China
mailto: checcy@public.hr.hl.cn
ICQ: 5116726

--
☆ 来源:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: checcy@public.hr.hl.]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.949毫秒