CRect


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: CRect

  1. #1
    Nick Guest

    CRect


    When using CWnd::Create how can you change the rect parameter. Instead of
    using CFrameWnd::rectDefault, i want a rectangle (0,0,248,130). I have tried
    creating a CRect, but i get an error saying that i convert from 'class CRect
    *' to 'struct tagRECT'.

  2. #2
    Brad Isaacs Guest

    Re: CRect


    Dear Nick,
    >
    >When using CWnd::Create how can you change the rect parameter. Instead of
    >using CFrameWnd::rectDefault, i want a rectangle (0,0,248,130).


    Perhaps you can use this as a demonstration and add in the pieces you need
    for your code.

    Hope this helps you,
    Brad Isaacs
    <<<<<<<<<<<<<<<<< SEE BELOW CODE >>>>>>>>>>>>>>>>>>>>>>>>>>>

    1: #include <iostream.h>
    2:
    3: typedef unsigned short int USHORT;
    4: typedef unsigned long int ULONG;
    5: enum BOOL { FALSE, TRUE};
    6: enum CHOICE { DrawRect = 1, GetArea,
    7: GetPerim, ChangeDimensions, Quit};
    8: // Rectangle class declaration
    9: class Rectangle
    10: {
    11: public:
    12: // constructors
    13: Rectangle(USHORT width, USHORT height);
    14: ~Rectangle();
    15:
    16: // accessors
    17: USHORT GetHeight() const { return itsHeight; }
    18: USHORT GetWidth() const { return itsWidth; }
    19: ULONG GetArea() const { return itsHeight * itsWidth; }
    20: ULONG GetPerim() const { return 2*itsHeight + 2*itsWidth; }
    21: void SetSize(USHORT newWidth, USHORT newHeight);
    22:
    23: // Misc. methods
    24: void DrawShape() const;
    25:
    26: private:
    27: USHORT itsWidth;
    28: USHORT itsHeight;
    29: };
    30:
    31: // Class method implementations
    32: void Rectangle::SetSize(USHORT newWidth, USHORT newHeight)
    33: {
    34: itsWidth = newWidth;
    35: itsHeight = newHeight;
    36: }
    37:
    38:
    39: Rectangle::Rectangle(USHORT width, USHORT height)
    40: {
    41: itsWidth = width;
    42: itsHeight = height;
    43: }
    44:
    45: Rectangle::~Rectangle() {}
    46:
    47: USHORT DoMenu();
    48: void DoDrawRect(Rectangle);
    49: void DoGetArea(Rectangle);
    50: void DoGetPerim(Rectangle);
    51:
    52: void main ()
    53: {
    54: // initialize a rectangle to 10,20
    55: Rectangle theRect(30,5);
    56:
    57: USHORT choice = DrawRect;
    58: USHORT fQuit = FALSE;
    59:
    60: while (!fQuit)
    61: {
    62: choice = DoMenu();
    63: if (choice < DrawRect || choice > Quit)
    64: {
    65: cout << "\nInvalid Choice, please try again.\n\n";
    66: continue;
    67: }
    68: switch (choice)
    69: {
    70: case DrawRect:
    71: DoDrawRect(theRect);
    72: break;
    73: case GetArea:
    74: DoGetArea(theRect);
    75: break;
    76: case GetPerim:
    77: DoGetPerim(theRect);
    78: break;
    79: case ChangeDimensions:
    80: USHORT newLength, newWidth;
    81: cout << "\nNew width: ";
    82: cin >> newWidth;
    83: cout << "New height: ";
    84: cin >> newLength;
    85: theRect.SetSize(newWidth, newLength);
    86: DoDrawRect(theRect);
    87: break;
    88: case Quit:
    89: fQuit = TRUE;
    90: cout << "\nExiting...\n\n";
    91: break;
    92: default:
    93: cout << "Error in choice!\n";
    94: fQuit = TRUE;
    95: break;
    96: } // end switch
    97: } // end while
    98: } // end main
    99:
    100:
    101: USHORT DoMenu()
    102: {
    103: USHORT choice;
    104: cout << "\n\n *** Menu *** \n";
    105: cout << "(1) Draw Rectangle\n";
    106: cout << "(2) Area\n";
    107: cout << "(3) Perimeter\n";
    108: cout << "(4) Resize\n";
    109: cout << "(5) Quit\n";
    110:
    111: cin >> choice;
    112: return choice;
    113: }
    114:
    115: void DoDrawRect(Rectangle theRect)
    116: {
    117: USHORT height = theRect.GetHeight();
    118: USHORT width = theRect.GetWidth();
    119:
    120: for (USHORT i = 0; i<height; i++)
    121: {
    122: for (USHORT j = 0; j< width; j++)
    123: cout << "*";
    124: cout << "\n";
    125: }
    126: }
    127:
    128:
    129: void DoGetArea(Rectangle theRect)
    130: {
    131: cout << "Area: " << theRect.GetArea() << endl;
    132: }
    133:
    134: void DoGetPerim(Rectangle theRect)
    135: {
    136: cout << "Perimeter: " << theRect.GetPerim() << endl;
    137: }



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center