CRect rect(10, 20, 50, 60); // create a rectangle with left=10, top=20, right=50, bottom=60 int width = rect.GetWidth(); // retrieve the width of the rectangle
CRect rect(0, 0, 800, 600); // create a rectangle with left=0, top=0, right=800, bottom=600 int width = rect.GetWidth(); // retrieve the width of the rectangle int height = rect.Height(); // retrieve the height of the rectangle float aspectRatio = (float)width / (float)height; // calculate the aspect ratio by dividing the width by the heightIn this example, we create a CRect object with left=0, top=0, right=800, bottom=600. We retrieve the width and height of the rectangle using the CRect GetWidth and Height functions, respectively. We then calculate the aspect ratio by dividing the width by the height, and store the result in a float variable. Both of these code examples use the CRect GetWidth function, which is a member function of the CRect class in the MFC library.