So, I need to make a program that draws a finite automata from the input data.
I had some experience with the graphics.h header but as far as I know it's a Borland only header and VC++ doesn't support it. So I was wondering, is there a way to draw some simple shapes and lines on VC++, besides using OpenGL?

Thanks, I'll give it a try. :)

Does anyone know if I can draw on a window (I mean a window forms application)? I remember using a component TDrawingBox in Borland C++, maybe there is a similar one in Visual C++ that I can use.

Edited 5 Years Ago by Basteon: n/a

See this: http://www.bobpowell.net/faqmain.htm

Caveat is the examples are in C# and VB.NET, but the usual dot used for namespace in C# changes to C++ :: ,and dot used for member method in C# changes to -> (if the variable in question is a pointer) will apply. Look on MSDN to confirm the syntax if need be.

I did some more research on the web and found this topic about shapes in Microsoft's MSDN Library "Shapes and Basic Drawing in WPF Overview". It seems that the only way to draw in a window is by using .Net and XAML. Typical for Microsoft, always making things more complicated than they aleready are.

If someone knows another way of drawing on a Form please respond, I would really apreciate'it.

You don't need to do it in WPF (using that with C++ is one of those things that's theoretically possible, but not really doable anyway), the GDI+ stuff works in C++/CLI. I'll try to throw together a sample at some point.

Here's a sample that moves a circle around the window when you press the button.

private: System::Void Form1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) 
{
    //get this event from the right hand side of the screen in the form design    
    //  window, click on the the lightening bolt and double click the cell next to 
     //the Paint()
				 
    Graphics ^ g = e->Graphics; //get the graphics handle from the form

    Random ^ rand = gcnew Random(); //random number generator

    g->DrawEllipse(gcnew Pen(Color::Black),
    Rectangle(rand->Next(0,ClientRectangle.Height),rand 
    ->Next(0,ClientRectangle.Width),10,10)); //make a circle in a 10x10 box at some 
//point over the window (box has upper left hand corner coordinate specified).  
//Sometimes it overlaps off the screen, but you get the idea

 //this normally requires a handle to a RectangleF (a rectangle with float coords), but this is an overload.
				 
}

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
{
   Invalidate(); //forces Paint() event to be called
}

(the lines are too long so it looks like hell, but you get the idea).

See if that gets you started in the right direction and you can start translating the Bob Powell tutorial (or one of your choosing) into C++. That graphics object holds all of the methods (drawellipse, fillellipse,etc.). The graphics object only comes from the Paint method, so you'll have to use Invalidate() in your other methods to control it.

Edited 5 Years Ago by jonsca: n/a

hi
iam new to c++ i want to draw a circle in c++ using microsoft visual c++.when i use graphics.h its not sopporting.what can i do now please any one help.

This question has already been answered. Start a new discussion instead.