SgtMe
Nearly a Posting Virtuoso
1,205 posts since Oct 2009
Reputation Points: 68
Solved Threads: 85
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.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
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.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
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.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581