Implementing Autoclik’s SetAllProps

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

  1. From the View menu, click ClassWizard.

  2. Click the Automation tab.

  3. Select CAutoClickDoc in the Class name box, if it is not already selected.

  4. Click Add Method.

    The Add Method dialog box appears.

  5. In the External name box, type SetAllProps. Accept ClassWizard’s proposal to reuse this as the Internal Name, which is the name of the class member function.

  6. In the Return type box, select void.

  7. Click in the Parameter list box to begin entering information for the first parameter of the SetAllProps method.

    This will highlight the first blank row in the Parameter box.

    • Under the Name heading, type x in the Name box.

    • If necessary, click under the Type heading, and select short.
  8. Repeat step 7 for the y parameter, entering it in the row under the x parameter.

  9. Add the third parameter, text, selecting LPCTSTR from the Type drop-down list box.

  10. Click OK.

    This returns you to the Automation tab of ClassWizard, which shows the following implementation:

    void SetAllProps(short x, short y, LPCTSTR text);
    
  11. Click Edit Code.

    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
    }
    
  12. Implement the handler with the following code:
    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.