home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / com / acdual / server / clikpnt.cpp < prev    next >
C/C++ Source or Header  |  1998-04-02  |  5KB  |  166 lines

  1. // ClikPnt.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "AutoClik.h"
  15. #include "ClikPnt.h"
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CAutoClickPoint
  24.  
  25. IMPLEMENT_DYNCREATE(CAutoClickPoint, CCmdTarget)
  26.  
  27. CAutoClickPoint::CAutoClickPoint()
  28. {
  29.     EnableAutomation();
  30.  
  31.     // To keep the application running as long as an OLE automation
  32.     //  object is active, the constructor calls AfxOleLockApp.
  33.  
  34.     AfxOleLockApp();
  35. }
  36.  
  37. CAutoClickPoint::~CAutoClickPoint()
  38. {
  39.     // To terminate the application when all objects created with
  40.     //  with OLE automation, the destructor calls AfxOleUnlockApp.
  41.  
  42.     AfxOleUnlockApp();
  43. }
  44.  
  45. void CAutoClickPoint::OnFinalRelease()
  46. {
  47.     // When the last reference for an automation object is released
  48.     //  OnFinalRelease is called.  This implementation deletes the
  49.     //  object.  Add additional cleanup required for your object before
  50.     //  deleting it from memory.
  51.  
  52.     delete this;
  53. }
  54.  
  55.  
  56. BEGIN_MESSAGE_MAP(CAutoClickPoint, CCmdTarget)
  57.     //{{AFX_MSG_MAP(CAutoClickPoint)
  58.         // NOTE - the ClassWizard will add and remove mapping macros here.
  59.     //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61.  
  62. BEGIN_DISPATCH_MAP(CAutoClickPoint, CCmdTarget)
  63.     //{{AFX_DISPATCH_MAP(CAutoClickPoint)
  64.     DISP_PROPERTY(CAutoClickPoint, "x", m_x, VT_I2)
  65.     DISP_PROPERTY(CAutoClickPoint, "y", m_y, VT_I2)
  66.     //}}AFX_DISPATCH_MAP
  67. END_DISPATCH_MAP()
  68.  
  69. // DUAL_SUPPORT_START
  70. // Original Code:
  71. //     // Note: we add support for IID_IAutoClickPoint to support typesafe binding
  72. //     //  from VBA.  This IID must match the GUID that is attached to the
  73. //     //  dispinterface in the .ODL file.
  74. //
  75. //     // {0368D830-A050-11CE-B0F3-00AA006C28B3}
  76. //     static const IID IID_IAutoClickPoint =
  77. //     { 0x368d830, 0xa050, 0x11ce, { 0xb0, 0xf3, 0x0, 0xaa, 0x0, 0x6c, 0x28, 0xb3 } };
  78. //
  79. //     BEGIN_INTERFACE_MAP(CAutoClickPoint, CCmdTarget)
  80. //          INTERFACE_PART(CAutoClickPoint, IID_IAutoClickPoint, Dispatch)
  81. //     END_INTERFACE_MAP()
  82.  
  83. // Note: we add support for DIID_IAutoClickPoint to support typesafe binding
  84. // from VBA.  We add support for IID_IDualAutoClickPoint to support our
  85. // dual interface. See ACDual.H for the definition of DIID_IAutoClickPoint
  86. // and IID_IDualAutoClickPoint.
  87. //
  88. // DUAL_ERRORINFO_PART indicates we support OLE Automation
  89. // error handling.
  90. //
  91.  
  92. BEGIN_INTERFACE_MAP(CAutoClickPoint, CCmdTarget)
  93.     INTERFACE_PART(CAutoClickPoint, DIID_IAutoClickPoint, Dispatch)
  94.     INTERFACE_PART(CAutoClickPoint, IID_IDualAutoClickPoint, DualAutoClickPoint)
  95.     DUAL_ERRORINFO_PART(CAutoClickPoint)
  96. END_INTERFACE_MAP()
  97. // DUAL_SUPPORT_END
  98.  
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CAutoClickPoint message handlers
  101.  
  102. // DUAL_SUPPORT_START
  103.  
  104. // delegate standard IDispatch methods to MFC IDispatch implementation
  105. DELEGATE_DUAL_INTERFACE(CAutoClickPoint, DualAutoClickPoint)
  106.  
  107. // Our method and property functions can generally just
  108. // delegate back to the methods we generated using
  109. // ClassWizard. However, if we set up properties to
  110. // access variables directly, we will need to write the
  111. // code to get/put the value into the variable.
  112.  
  113. STDMETHODIMP CAutoClickPoint::XDualAutoClickPoint::put_x(short newX)
  114. {
  115.     METHOD_PROLOGUE(CAutoClickPoint, DualAutoClickPoint)
  116.  
  117.     TRY_DUAL(IID_IDualAutoClickPoint)
  118.     {
  119.         pThis->m_x = newX;
  120.         return NOERROR;
  121.     }
  122.     CATCH_ALL_DUAL
  123. }
  124.  
  125. STDMETHODIMP CAutoClickPoint::XDualAutoClickPoint::get_x(short FAR* retval)
  126. {
  127.     METHOD_PROLOGUE(CAutoClickPoint, DualAutoClickPoint)
  128.  
  129.     TRY_DUAL(IID_IDualAutoClickPoint)
  130.     {
  131.         *retval = pThis->m_x;
  132.         return NOERROR;
  133.     }
  134.     CATCH_ALL_DUAL
  135. }
  136.  
  137. STDMETHODIMP CAutoClickPoint::XDualAutoClickPoint::put_y(short newY)
  138. {
  139.     METHOD_PROLOGUE(CAutoClickPoint, DualAutoClickPoint)
  140.  
  141.     TRY_DUAL(IID_IDualAutoClickPoint)
  142.     {
  143.         pThis->m_y = newY;
  144.         return NOERROR;
  145.     }
  146.     CATCH_ALL_DUAL
  147. }
  148.  
  149. STDMETHODIMP CAutoClickPoint::XDualAutoClickPoint::get_y(short FAR* retval)
  150. {
  151.     METHOD_PROLOGUE(CAutoClickPoint, DualAutoClickPoint)
  152.  
  153.     TRY_DUAL(IID_IDualAutoClickPoint)
  154.     {
  155.         *retval = pThis->m_y;
  156.         return NOERROR;
  157.     }
  158.     CATCH_ALL_DUAL
  159. }
  160.  
  161. // Implement ISupportErrorInfo to indicate we support the
  162. // OLE Automation error handler.
  163. IMPLEMENT_DUAL_ERRORINFO(CAutoClickPoint, IID_IDualAutoClickPoint)
  164.  
  165. // DUAL_SUPPORT_END
  166.