Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using graphics.h 1

Status
Not open for further replies.

logi2000

Programmer
Jun 17, 2003
221
CR
can i use the graphics.h library in MS Visual C++, or is that exclusive for borland ?

thanks
 
Graphics.h is so ancient you should look into using something else, even if you can use it. A friend tried and said it wouldn't let him use it with Visual Studio 6, I think. Anyway, if you want to do something with graphics, look into OpenGL if it must be cross platform, or you can check out the win32 GDI or DirectX if not.
 
is exclusive for borland

Ion Filipski
1c.bmp
 
is there any library i could use instead of graphics.h, the program i need to do is very simple, i just need to draw lines on the computer screen, and need to fill a pattern of a polygon, i dont need to do anything compplicated.

any suggestions ?
 
Let the AppWizard generate a SDI application for you. Override the view's OnDraw. Draw your polygons and whatever using the GDI interface. Search MSDN on CDC and see what methods that class provides.

/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
SDI = Single Document Interface
It's the simplest form of an MFC doc/view application, having a single document and (by defualt) one single view. Like notepad.

Use the AppWizard to genereate an MFC applicaton (exe). Select the Single Document option. Press Finish.

Find the view class that has been generated and override its OnDraw method.

/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
I'd say GDI. You calso may ose OpenGL or DirectX for graphics.

Ion Filipski
1c.bmp
 
do it sure work with Microsoft VisualStudio? It's a bit intrigating for me...

Ion Filipski
1c.bmp
 
Yes, but you need to add some code to the beginning of winbgim.cpp. You must define the colors as the numbers 0 to 15. It is done in winbgim.cpp with enum(), but it doens't work right. Just define each color in winbgim.cpp using the existing enum statement, and the each color used in your program. Then you can use the graphics.h functions(make sure you #include <winbgim.h>).
 
Ok, I'll try that, by the way, it is for console of for Windows applications?

Ion Filipski
1c.bmp
 
It needs to be a Windows application. You still use a main() function for your program but the graphics library uses windows api.
 
For what you are doing (just lines and shapes), it should be easier to use winbgim. There are simple functions to draw simple graphics, and they are easy to use. There is a list of all the functions at the site I mentioned earlier.
 
Obviously "easy" is in the eye of the beholder.
Code:
pDC->MoveTo(...);
pDC->LineTo(...);

isn't all that tricky...

/Per
[sub]
&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;[/sub]
 
Well, yeah, but
Code:
line(0,0,100,100);
is easy too. By the way, I meant to say that winbgim is just simplified functions made from win32.
 
but how will you indicate the window where line(0,0,100,100); will have effects?

Ion Filipski
1c.bmp
 
You'll have to look at the website to learn all the functions. If you want a good example other than the ones on the site, here is the first program that I made with it.
Code:
#include <winbgim.h>
#include <iostream.h>
#include <stdlib.h>
#include <time.h>

bool blue_clicked = false;
void click_handler(int x, int y)
{
    if (getpixel(x,y) == BLUE)
        blue_clicked = true;
}

void main()
{
	srand(time(NULL));

	short x=1;
	initwindow(600,400);
	registermousehandler(WM_LBUTTONDOWN, click_handler);
	blue_clicked = false;

	setcolor(BLUE);
	setfillstyle(SOLID_FILL, BLUE);
	fillellipse(getmaxx()/2, 25, 25, 25);

	while (!blue_clicked)
	{
		setcolor(x);
		line(0,0,getmaxx(),getmaxy());
		line(getmaxx(),0,0,getmaxy());

		setfillstyle(SOLID_FILL, COLOR(rand()%250,rand()%250,rand()%250));
		fillellipse(getmaxx()/2, getmaxy()/2, 100, 100);
		x++;
		if (x==16)
			x=1;
		delay(250);
	}
	closegraph();
}
Just make sure you create a Win32 Application program and include winbgim.cpp with the modification I mentioned earlier.
 
I see no advantages of using this library and not using GDI. In GDI you only pass one more parameter to the same functions where you indicate the context where the picture will be created. So, why is there required some ancient like library what does the same as GDI but has severe restrictions?

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top