220 likes | 276 Views
Learn about EzWindows library objects and their initialization, including SimpleWindow and RectangleShape. Explore examples and syntax for initializing objects with multiple attributes. Discover member functions for processing messages and manipulating objects.
E N D
Chapter 3: EzWindows • Page 130 to 141
EzWindows Library Objects • Definitions are the same form as other objects • Example SimpleWindow W; • Most non-fundamental classes have been created so that an object is automatically initialized to a sensible value • SimpleWindow objects have member functions to process messages to manipulate the objects • Most important member function is Open() which causes the object to be displayed on the screen • Example W.Open();
Initialization • Class objects may have several attributes to initialize • Syntax for initializing an object with multiple attributes Type Identifier(Exp1, Exp2, ..., Expn); • SimpleWindow object has several optional attributes SimpleWindow W("Window Fun", 8, 4); • First attribute • Window banner • Second attribute • Width of window in centimeters • Third attribute • Height of window in centimeters
An EzWindows Program #include <iostream> using namespace std; #include "ezwin.h" int ApiMain() { SimpleWindow W("A Window", 12, 12); W.Open(); cout << "Enter a character to exit" << endl; char a; cin >> a; return 0; }
This should be a comment in all your EZWindows Programs //To compile this program you must: //1. If the .h files are not in same subdirectory as your program then //goto Project, Settings..., C/C++ tab, choose Preprocessor from the Category //pulldown menu, and under Additional Include Directories //add C:\Program Files\C++ProgramDesign\ezwin\include //2. goto Project, Add to Project, File. From the Look In: pulldown menu //goto subdirectory C:\Program Files\C++ProgramDesign\ezwin\lib. //From pull down menu for Files of Type:, choose All Files. File Ezwinvc50.lib //should appear in the listing box. Choose that file (Ezwinvc50.lib) and //select OK button. //3. The environment should be ready for use.
RectangleShape Objects • EzWindows also provides RectangleShape for manipulating rectangles • RectangleShape objects can specify the following attributes • SimpleWindow object that contains the rectangle (mandatory) • Offset from left edge of the SimpleWindow • Offset from top edge of the SimpleWindow • Offsets are measured in centimeters from rectangle center • Width in centimeters • Height in centimeters • Color • color is an EzWindows type
RectangleShape Objects • Examples SimpleWindow W1("My Window", 20, 20); SimpleWindow W2("My Other Window", 15, 10); RectangleShape R(W1, 4, 2, Blue, 3, 2); RectangleShape S(W2, 5, 2, Red, 1, 1); RectangleShape T(W1, 3, 1, Black, 4, 5); RectangleShape U(W1, 4, 9);
#include <iostream> using namespace std; #include "rect.h" int ApiMain() { Position pos0(1, 1); SimpleWindow W1("First Window", 10, 10, pos0); Position pos1(12, 8); SimpleWindow W2("Second Window", 15, 10, pos1); W1.Open(); W2.Open(); RectangleShape R(W1, 4, 6, Blue, 3, 2); RectangleShape S(W2, 5, 2, Red, 1, 1); RectangleShape T(W1, 4, 2, Black, 4, 2); RectangleShape U(W1, 4, 9); R.Draw(); S.Draw(); T.Draw(); U.Draw(); cout << "Enter a character to exit" << endl; char Response; cin >> Response; return 0; } Example – ez6.cpp
RectangleShape Objects • Some RectangleShape member functions for processing messages • Draw() • Causes rectangle to be displayed in its associated window • GetWidth() • Returns width of object in centimeters • GetHeight() • Returns height of object in centimeters • SetSize() • Takes two attributes -- a width and height -- that are used to reset dimensions of the rectangle
Another EzWindows Program #include <iostream> using namespace std; #include "rect.h" int ApiMain() { SimpleWindow W("Rectangular Fun", 12, 12); W.Open(); RectangleShape R(W, 5.0, 2.5, Blue, 1, 2); R.Draw(); cout << "Enter a character to exit" << endl; char Response; cin >> Response; return 0; }
Chapter 4: EzWindows • Page 210 to 214
Displaying a Diagonal SimpleWindow W("One diagonal", 5.5, 2.25); W.Open(); for (int j = 1; j <= 3; ++j) { float x = j * 0.75 + 0.25; float y = j * 0.75 - 0.25; float Side = 0.4; RectangleShape S(W, x, y, Blue, Side, Side); S.Draw(); }
Displaying Three Diagonals The scope of i includes the inner loop. SimpleWindow W("Three diagonals", 6.5, 2.25); W.Open(); for (int i = 1; i <= 3; ++i) { for (int j = 1; j <= 3; ++j) { float x = i - 1 + j * 0.75 + 0.25; float y = j * 0.75 - 0.25; float Side = 0.4; RectangleShape S(W, x, y, Blue, Side, Side); S.Draw(); } } The scope of j is just the inner loop.
Chapter 6: EzWindows • Page 319 to 321 • Page 333 to 341
Passing Constant Rectangles void DrawBoxes(const RectangleShape &R1, const RectangleShape &R2) { R1.Draw(); R2.Draw(); } int ApiMain() { SimpleWindow Demo("Demo Program"); Demo.Open(); RectangleShape Rect1(Demo, 3, 2, Blue); RectangleShape Rect2(Demo, 6, 5, Yellow); DrawBoxes(Rect1, Rect2); return 0; }