In the following procedure, you’ll add and implement SetAllProps
as a method. SetAllProps
sets the m_pt
and m_str
member variables, and updates the view.
To add a method with parameters
The Add Method dialog box appears.
SetAllProps
. Accept ClassWizard’s proposal to reuse this as the Internal Name, which is the name of the class member function.SetAllProps
method.This will highlight the first blank row in the Parameter box.
x
in the Name box.y
parameter, entering it in the row under the x
parameter.text
, selecting LPCTSTR from the Type drop-down list box.This returns you to the Automation tab of ClassWizard, which shows the following implementation:
void SetAllProps(short x, short y, LPCTSTR text);
This takes you to the stub handler that ClassWizard created in AutoClickDoc.cpp:
void CAutoClickDoc::SetAllProps(short x, short y, LPCTSTR text)
{
// TODO: Add your dispatch handler code here
}
m_pt.x = x;
m_pt.y = y;
m_str = text;
Refresh();
Take a look at the dispatch map for the SetAllProps
method (in AutoClickDoc.cpp):
BEGIN_DISPATCH_MAP(CAutoClickDoc, CDocument)
//{{AFX_DISPATCH_MAP(CAutoClickDoc)
...
DISP_FUNCTION(CAutoClickDoc, "SetAllProps", SetAllProps, VT_EMPTY,
VTS_I2 VTS_I2 VTS_BSTR)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
The last four parameters of the DISP_FUNCTION entry for SetAllProps
list the return type, VT_EMPTY for void, followed by the three parameters. You do not need to interpret the parameter types in dispatch maps; the framework interprets them at run time. But you can see that VTS_I2 represents short and VTS_BSTR represents LPCTSTR.
The last method you’ll implement is ShowWindow.