CapitolSoft Banner
 

 

In the previous section Part 3: Examining Control Code, we have seen the code block that performs drawing on control:

void CCircle::DrawControl(CDC* pDC, CRect rect)
{
    pDC->FillSolidRect(rect, RGB(192, 192, 192));
    pDC->Ellipse(rect);
    pDC->DrawText(_T("C++ Rules!!"), rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}

The "DrawControl" function takes two parameters. the first one is a CDC pointer. If you are not familiar with CDC, it's a MFC class that encapsulates a Windows device context and thus can be used to perform a lot of drawing functions. You can find more on the CDC class on the web in the following link:

http://msdn.microsoft.com/library/devprods/vs6/visualc/vcmfc/_mfc_cdc.htm

The send parameter is a CRect class that carries the bounding coordinates of the control.

Inside the ::DrawControl function, you will find 3 CDC function calls:

"FillSolidRect" fills the background of the circle by gray color [RGB(192, 192, 912)],

"Ellipse" draws an ellipse inside the control

and "DrawText" prints some text ["C++ Rules"] at the center of the control.

You can modify these function calls to perform a different kind of drawing. For example, if you want to paint your control's background with red color, then you should change the "FillSolidRect" function call like the following:

    pDC->FillSolidRect(rect, RGB(255, 0, 0));

Additionally, if you want to draw a rectangle instead of a ellipse / circle, then you need to replace

   pDC->Ellipse(rect);

with

   pDC->Rectangle(rect);

In summary, you can use any member function of the MFC's "CDC"" class to modify drawing behavior of the "Circle" control.

In addition to CDC's class member functions, you can use RFC's drawing utility functions. For example you can display a bitmap on your  control by calling the following function:

CRTools::DisplayBitmap(pDC, CPoint(rect.left, rect.top), "c:\\mypicture.bmp");

Where "c:\\mypicture.bmp" is a bitmap file path.

Next >> Part 5: Adding a Property to the New Control

Related Links:

Control Development Kit (CDK) Home

 

 

Microsoft Visual C++, Microsoft Visual Basic and Microsoft Visual Studio are registered trademarks of Microsoft Corporation.
Copyright © 1998-2000 Capitolsoft Corporation. All rights reserved.
Disclaimer: Capitolsoft Corporation is an independent business organization incorporated with the State Commission of Virginia and hence has no connection with U.S. Capitol or any other federal agency of U.S. government. Opinions expressed by the individuals in this site are of their own alone and hence do not necessarily reflect the views of Capitolsoft Corporation.

 

This page was last updated on November 21, 2005
Hit Counter