Completing the GetNote and SetNote Functions

To complete the GetNote and SetNote functions, add the m_note member variable to the CCircCtrl class to hold the value of the Note property. The GetNote and SetNote functions will be modified to use this member variable.

Because Note is a persistent property, the SetNote function must call the SetModifiedFlag function to set the modified flag. A call to the SetModifiedFlag function is already included in the SetNote function created by ClassWizard. Because the Note property affects the visual appearance of the control, the SetNote function must also call the InvalidateControl function to redraw the control.

To complete the GetNote and SetNote functions

  1. Add the following line to CIRCCTL.H:
        CString m_note;
    

    as shown in the following example:

    class CCircCtrl : public COleControl
    {
    ...
    protected:
        ~CCircCtrl();
        void GetDrawRect(CRect* rc);
        short m_circleOffset;
        BOOL InBounds(short nOffset);
        BOOL InCircle(CPoint& point);
        void FlashColor(CDC* pdc);
        CString m_note;
    ...
    };
    
  2. Modify the return statement in the GetNote function in CIRCCTL.CPP as shown below:
    BSTR CCircCtrl::GetNote()
    {
        return m_note.AllocSysString();
    }
    
  3. Modify the SetNote function in CIRCCTL.CPP by adding the if statement shown below:
    void CCircCtrl::SetNote(LPCTSTR lpszNewValue)
    {
        if (m_note != lpszNewValue)
        {
            m_note = lpszNewValue;
            SetModifiedFlag();
            InvalidateControl();
        }
    }