Can't be able to use "graphics.h" in Code Block ?

I'm trying to use "graphics.h" just for learning purpose. I'm trying to draw a line but "Code Block 13.12" gives this error

"drawing operation was attempted when there was no current window"
http://postimg.org/image/hselc60ux/

Code I'm using:

#include<graphics.h>
int main()
{
line(0,0,640,480);
return 0;
}

As Code Block by default doesn't have "graphics.h". So, I followed One tutorial tom setup graphics.h in Code Block which has the following steps.

1. Download "WinBGIm_Library6_0_Nov2005.rar" from http://winbgim.codecutter.org/

2. After extraction put "graphics.h" & "winbgim.h" in "C:\Program Files\CodeBlocks\MinGW\include" folder

3. "libbgi.a" in "C:\Program Files\CodeBlocks\MinGW\lib" folder

4. Setting -> Compiler -> Global compiler setting
5.under "Link Libraries" section add
"C:\Program Files\CodeBlocks\MinGW\include"

6. under "Other linker options" section add
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

7. Open "graphics.h" from "C:\Program Files\CodeBlocks\MinGW\include" in notepad and jump to line 302 and edit it to

int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,

Please tell whats the problem
You didn't initialise your window.
As Code Block by default doesn't have "graphics.h".
And it is logical because graphics.h is non-standard external library.
OPs description includes downloading and installing WinBGIm, which is a modern port of the old BGI (Borland Graphics) library.

Make sure to peruse the documentation at http://www.cs.colorado.edu/~main/cs1300/doc/bgi/index.html

It is full of examples.

To initialize the graphics library you will probably want to use the initwindow() function.
http://www.cs.colorado.edu/~main/cs1300/doc/bgi/initwindow.html
(That creates a graphics window you can draw a line in, in contrast to a fullscreen graphics mode.) Take a look at the first example to see how create a window and draw a line.

Hope this helps.
you could have just put the file in the same folder as the .cbp file and in the main.cpp file said #include "graphics.h" .
Last edited on
@Duoas, Upon running this code

#include <graphics.h>
int main()
{
/* initialize graphics window at 400 x 300 */
initwindow(400, 300);

/* draw a line */
line(0, 0, 100, 100);

/* clean up */
getch();
closegraph();
return 0;
}

I'm getting this new error message

"Test.exe" has stopped working and

http://postimg.org/image/yh2utnypr/
I've installed WinBGIm myself and see the same problem -- meaning something is wrong with the library. If I get time I'll figure it out for you, but you might ask your teacher. It is unlikely you are the only student with the issue.


Alright.. I just compiled from source. Chances are there is a mismatch with the GCC version used to create the binary you got from the WinBGIm site...

Give me a few minutes and I'll post the new binary for you (and your classmates) to grab.
Last edited on
Alright, you can grab the new WinBGIm here:

http://home.comcast.net/~michaelthomasgreer/temp/WinBGIm_GCC47.zip

Unzip and you'll find a new libbgi.a to replace the one you have now.

I'll keep this up for a while (at least a month), but not forever. (Otherwise the interwebs will start a whole bunch of people grabbing it all the time and Comcast will want to charge me more money.)

Hope this helps.
Kudos @Duoas
Thanx a lot, It worked. I've dwnloaded it. You can remove it now.
Well, let your classmates get it too... They're probably having the same problem you are. :-)
@Duos Oh no no not my classmates. Actually I've learned c++ way back 3-4 years. But didn't learn this part. There is one old project that I have, So I was thinking to improve its user interface with little bit of graphics.
Ah, I missed that in your first post. :-/

Well, glad to have helped.
:O)
Topic archived. No new replies allowed.