In the following procedure, you will expose m_str directly as a property and study how ClassWizard adds it to the dispatch map. You’ll then remove the redundant declaration you added earlier. Finally, you’ll change the dispatch map declaration from private to public to give the view access to m_str.
To directly expose the m_str member variable in the dispatch interface
The Add Property dialog box appears.
text1
.
Whereas you exposed m_pt
indirectly by using the Get/Set methods option, expose m_str
directly as a member variable.
m_text1
(which was based on the External name), with m_str
.
Soon you will see how to associate the text dispatch property with the m_str
member variable already declared in the document class.
This step is included for instructional purposes. You could have implemented an OnText1Changed
function by calling Refresh
, just as you did for SetX
and SetY
. If you do not implement a similar OnText1Changed
function, then you can see the different behavior when you drive AutoClik from an Automation client. When the Automation client updates the text, AutoClik does not automatically update its view as it does when the Automation client changes the x
or y
values. Instead, the Automation client must call the Refresh
method to update AutoClik’s view with the most recently changed text.
This returns you to the Automation tab, which now displays the three properties: text
, x
, and y
. The Implementation box for the text
variable shows:
CString m_str;
ClassWizard has declared the following members in the dispatch map:
//{{AFX_DISPATCH(CAutoClickDoc)
CString m_str;
afx_msg short GetX();
afx_msg void SetX(short nNewValue);
afx_msg short GetY();
afx_msg void SetY(short nNewValue);
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
At this point, the document header file declares m_str
twice. The first declaration is the one you originally wrote:
// Attributes
public:
CPoint m_pt;
CString m_str;
The second declaration is the one ClassWizard added above in the dispatch map.
CString m_str
declaration that you wrote, shown above. // Generated OLE dispatch map functions
This changes the declaration of the dispatch map from protected to public. This is necessary because m_str
had already been declared as public so it could be accessed by the view.