| To add a
            property to your RAD C++ control, you need to invoke the dialog by clicking the right
            mouse button on the control bitmap on the RadVC toolbox and then selecting "Add
            Property" context menu item: 
 The "Add Property" dialog box will
            now appear.  
 For our "Circle" control, we will
            add a property called "CircleShape". "CircleShape" is a Boolean type
            of property that defines the circular shape of the control. When this property is set as
            "TRUE", the circle is drawn as a perfect circle. The circle will be drawn within
            the bounding rectangle of the control. To determine how to draw the circle, you simply
            calculate he square region centered within the bounding rectangle of the control. When the
            "CircleShape" property is set to FALSE, an ellipse is drawn.   When Clicked on the "OK" button in
            "Add Property" dialog, RadVC opens the control implementation file (circle.cpp)
            and highlighting the "GetCircleShape" function.. 
              BOOL CCircle::GetCircleShape(){
 return m_CircleShape;
 }
 
 void CCircle::SetCircleShape(BOOL bCircleShape)
 {
 m_CircleShape = bCircleShape;
   Invalidate();}
 void CCircle::DrawControl(CDC* pDC, CRect
                rect){
      
                if(m_CircleShape)       
                {              
                int nWidth = rect.Width();              
                int nHeight = rect.Height();              
                if(nWidth > nHeight)              
                {                    
                rect.left = (nWidth - nHeight) / 2;          
                rect.right = rect.left + nHeight;              
                }     else if(nHeight
                > nWidth)              
                {                    
                rect.top = (nHeight - nWidth) / 2;          
                rect.bottom = rect.top + nWidth;              
                }       
                }pDC->FillSolidRect(rect, RGB(192, 192,
                192));
 pDC->Ellipse(rect);
 pDC->DrawText(_T("C++ Rules!!"),
                rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
 }
   
                Next >> Part 6: Adding an Event to the Control 
              Related Links:Control
                Development Kit (CDK) Home  |