In the following procedure, you will expose m_pt indirectly as a property and add code to implement it, while ClassWizard generates the stub handlers for it. ClassWizard enables you to implement methods and properties the same way you implement member functions.
To indirectly expose the m_pt member variable in the dispatch interface
The Add Property dialog box appears.
x
.
This returns you to the Automation tab. The new property, listed as x
in the Name list, is implemented with Get and Set member functions. The Implementation box shows:
short GetX();
void SetX(short nNewValue);
The gray glyph with a “C” indicates that there is code associated with these member functions.
return m_pt.x;
m_pt.x = nNewValue;
Refresh();
y
property, ending with:short CAutoClickDoc::GetY()
{
return m_pt.y;
}
void CAutoClickDoc::SetY(short nNewValue)
{
m_pt.y = nNewValue;
Refresh();
}
Note The x and y members of a point are declared as long in Win32. This may generate the following warning when you build the project:
warning C4244: 'return' : conversion from 'long' to 'short', possible loss of data
You can disregard the warning; it will not affect how Autoclik runs.
ClassView displays the new methods. You can examine AutoClickDoc.cpp to see how ClassWizard updated the dispatch map of the document class:
BEGIN_DISPATCH_MAP(CAutoClickDoc, CDocument)
//{{AFX_DISPATCH_MAP(CAutoClickDoc)
DISP_PROPERTY_EX(CAutoClickDoc, "x", GetX, SetX, VT_I2)
DISP_PROPERTY_EX(CAutoClickDoc, "y", GetY, SetY, VT_I2)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
You can see how the information you entered in ClassWizard is reflected in the dispatch map.