|
It turns out that OOP ("Object Oriented Programming") and Windows programming were made for
each other. Unfortunately, when Windows was developed by Microsoft, OOP had not really taken
hold. Therefore, it is up to you, as an application/system programmer, to "convert" standard
Window calls into reusable and convenient objects.
An aside: Microsoft is not stupid. After Windows was developed, they created a new product called
MFC ("Microsoft Foundation Classes"), which is an Object Oriented library that you can use to develop
window applications. Many Window programmers now use MFC instead of calling directly into the
"Platform SDK". Someday, you may use MFC as well. For now, using MFC as you learn is like
giving a child a calculator before teaching the child how to multiply.
In this lesson, we will focus on re-organizing your Window's program so that OOP begins
to become your preferred technique for Window's programming.
|
|
Item |
|
Time |
Description |
| |
|
1 | |
10 Mins |
Create a new window class that is based on your current window class. Call this new class
"mcTopLevelWindow". Modify MainApp.cpp so that an instance of this new window is created
instead of a mcBaiscWindow. Verify that your program works as before.
|
| |
|
2 | |
10 Mins |
Change the program so that your new class has it's own Paint() function. You will need to
change the base class slightly, by inserting the keyword "virtual". Why and where is
"virtual" needed?
|
| |
|
3 | |
10 Mins |
Change the program so that you can pass in a background color to your Create() funciton for your new class.
Then, change your Paint() function to color the entire window by filling a rectangle with the color.
Don't do this by changing the Create() function in mcBasicWindow. Will you need the "virtual" keyword
for this? How about a new variable member in your class? Hint: Use GetClientRect() to help create
your rectangle.
|
| |
|
4 | |
10 Mins |
Modify your MainApp.cpp so that two windows are created, with different colors, one green, and
the other red. Before you do this, read about Gdiplus::Color. Is there a way that you can
use Gdiplus::Color to specify the color without resorting to using numbers for red/green/blue?
(Answer: yes there is. Figure out how to do this.)
|
| |
| |
|