Saturday, May 7, 2011

C++ College OOP Project

Hey, today I want to share my last project with you, which is a home work for my OOP class in college.

The task was to show our teacher (Vladimir Nodelman)  that we understand the basics of OOP, which includes classes, inheritance and polymorphism. We were asked to come up with a subject for the task and I decided to implement a paint-like application with a couple of minor enhancements, like editing, dragging and removing of the already placed shapes.

For UI we were asked to use WINAPI library that we covered last semester.

I started with creating a base class for a shape and a number of derived classes, like rectangle, which inherits to rectangle_fill (colored rectangle), and a button that I created myself, so i could draw an icon in it.

To accomplish the polymorphism I created a shape list, which contains Pointers to all shapes.
Important: for the polymorphism to work you need to created the function you want to call with the base class as virtual functions and to call them through base class pointer.

In the base class I created a couple of virtual functions, like draw(HDC) which gets the device context and draws on it.
WINAPI event handling is used to catch events of Left Mouse Button Pressed/Released, Mouse Movement, Window Creation and more. Each event is handled accordingly.



Code                 Exe

No comments:

Post a Comment