home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / circ / cpevent.h < prev    next >
C/C++ Source or Header  |  1998-03-26  |  2KB  |  67 lines

  1. // cpevent.h : proxy for circ events
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12.  
  13. //////////////////////////////////////////////////////////////////////////////
  14. // CProxy_CircEvents
  15.  
  16. template <class T>
  17. class CProxy_CircEvents : public IConnectionPointImpl<T, &DIID__CircEvents, CComDynamicUnkArray>
  18. {
  19. public:
  20.     void Fire_Click()
  21.     {
  22.         // Dispatch ID : 0x1
  23.         T* pT = static_cast<T*>(this);
  24.         int i;
  25.         int nConnections = m_vec.GetSize();
  26.  
  27.         for (i = 0; i < nConnections; i++)
  28.         {
  29.             pT->Lock();
  30.             CComPtr<IUnknown> sp = m_vec.GetAt(i);
  31.             pT->Unlock();
  32.             IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
  33.             if (pDispatch != NULL)
  34.             {
  35.                 DISPPARAMS disp = { NULL, NULL, 0, 0 };
  36.                 pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  37.             }
  38.         }
  39.  
  40.     }
  41.     void Fire_KeyPress(short KeyAscii)
  42.     {
  43.         // Dispatch ID : 0x2
  44.         T* pT = static_cast<T*>(this);
  45.         int i;
  46.         CComVariant* pvars = new CComVariant[1];
  47.         int nConnections = m_vec.GetSize();
  48.  
  49.         for (i = 0; i < nConnections; i++)
  50.         {
  51.             pT->Lock();
  52.             CComPtr<IUnknown> sp = m_vec.GetAt(i);
  53.             pT->Unlock();
  54.             IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
  55.             if (pDispatch != NULL)
  56.             {
  57.                 pvars[0].vt = VT_I2;
  58.                 pvars[0].iVal= KeyAscii;
  59.                 DISPPARAMS disp = { pvars, NULL, 1, 0 };
  60.                 pDispatch->Invoke(0x2, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  61.             }
  62.         }
  63.         delete[] pvars;
  64.  
  65.     }
  66. };
  67.