banner.jpg (64767 bytes)
Open Architecture
Control Development Kit
RAD Foundation Class
Enhanced IntelliSense
Migration Center


Examining Control Code

Now that you know how to create a skeleton RAD C++ control, it's time to look at the RadVC generated control code that make it function. While you will be developing the control further by adding more features to it, the understanding of the control code will help you to write better controls.


RadVC generates 4 files for any skeleton RAD C++ control you create. For our "Circle" control, here is the list of files RadVC generated for us.

Circle.h Header file. The control class "CCircle" is declared in this file.
Circle.cpp Implementation file. "CCircle" is implemented here.
Circle.rc Resource file. Control specific resources (e.g. bitmap, icon, strings etc) are defined here.
Circle.rh Resource header file. Control resource ID's are defined here.
Circle.bmp Control tool bitmap.

The two files that you will be playing most with are the header and the implementation files (circle.h and circle.cpp respectively).  You will be modifying  these files to add more features and attributes (e.g. properties/methods/events) to the control. Here is the listing of these two files.

CCircle Control Code

Header (Circle.h) Implementation (Circle.cpp)
class CCircle : public CWnd
// Construction
    CCircle(); // standard constructor
    virtual ~CCircle();
    BOOL Create(void* pParent, UINT nID, RECT rect);




    // Controls

    void    DrawControl(CDC* pDC, CRect rect);
    void SetProperties();
    virtual void CreateControls();
    RECT    m_rect;
    UINT    m_nID;
    void*    m_pParent;


    // Generated message map functions
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    m_rect = CRect(0, 0, 312, 213);
    m_nID = 0;
    m_pParent = NULL;

    //{{AFX_MSG_MAP(CCircle )

void CCircle::CreateControls()
void CCircle::SetProperties()

BOOL CCircle::Create(void* pParent, UINT nID, RECT rect)
    m_nID = nID;
    m_pParent = pParent;
    BOOL bRet = TRUE;
    bRet = CWnd::Create(NULL, NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP, rect, (CWnd*)pParent, nID);
    return bRet;
BOOL CCircle::OnEraseBkgnd(CDC* pDC)
    CRect rect;
    DrawControl(pDC, rect);
    return TRUE;

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


Couple of points to note about the generated code:

(1) Control Initialization: Initialize the any control data in the constructor CCircle::Circle().

(2) Control Creation: The control is created through a function called "Create". It has the following format:

      BOOL Create(void* pParent, UINT nID, RECT rect);

Our "Circle" control is a "CWnd" derived class, thus its "Create" function calls the same of the base class

    CWnd::Create(DWORD dwStyle, CRect rect, CWnd* pWnd, UINT nID);

After the control is successfully created, CCirclle::Create(..) calls "CreateControls()" to create its child controls and "SetProperties()" to set the properties of the control itself and all of its child controls.

CCircle::Create(..) function creates the Windows handle whereas CCircle::Circle() merely initializes control data. Thus any initialization that depends on a valid Windows handle should be made after CWnd::Create(..) function in CCircle::Create() and not in the constructor.

(3) Drawing: Our "Circle" control is drawn in the function ::DrawControl(..) function, which is called from ::OnEraseBkgnd(CDC* pDC) message handler. As you can see, RadVC generates the necessary code for handling WM_ERASEBKGND Windows message in the control files. You will learn more on how to modify the code in ::DrawControl(..) function later in Part 4: Drawing on the New Control

(4) Child Controls: RadVC inserts declaration code for its child controls in the following comment block: (circle.h):

    // Controls

Controls are created in ::CreateControls() function in circle.cpp.


(5) Control Attributes: RadVC inserts code to declare properties, methods and events in the following comment blocks (circle.h):




Later in the following links, you will learn more how you can add these attributes :

Part 5: Adding a Property to the New Control

Part 6: Adding an Event to the New Control

Part 7: Adding a Method to the New Control


Next >> Part 4: Drawing on 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