home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / interfac / idropsrc.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  3KB  |  141 lines

  1. /*
  2.  * IDROPSRC.CPP
  3.  *
  4.  * Template implementation of a DropSource object.  There is
  5.  * actually a full standard implementation of this interface here.
  6.  *
  7.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Microsoft
  10.  * Internet  :  kraigb@microsoft.com
  11.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  12.  */
  13.  
  14.  
  15. #include "idropsrc.h"
  16.  
  17.  
  18. /*
  19.  * CDropSource::CDropSource
  20.  * CDropSource::~CDropSource
  21.  *
  22.  * Constructor Parameters:
  23.  *  pObj            LPVOID back pointer to whatever we live with.
  24.  */
  25.  
  26. CDropSource::CDropSource(LPVOID pBack)
  27.     {
  28.     m_cRef=0;
  29.     m_pBack=pBack;
  30.     return;
  31.     }
  32.  
  33.  
  34. CDropSource::~CDropSource(void)
  35.     {
  36.     return;
  37.     }
  38.  
  39.  
  40.  
  41.  
  42. /*
  43.  * CDropSource::QueryInterface
  44.  * CDropSource::AddRef
  45.  * CDropSource::Release
  46.  *
  47.  * Purpose:
  48.  *  Non-delegating IUnknown members for CDropSource.
  49.  */
  50.  
  51. STDMETHODIMP CDropSource::QueryInterface(REFIID riid
  52.     , LPVOID *ppv)
  53.     {
  54.     *ppv=NULL;
  55.  
  56.     if (IID_IUnknown==riid || IID_IDropSource==riid)
  57.         *ppv=(LPVOID)this;
  58.  
  59.     if (NULL!=*ppv)
  60.         {
  61.         ((LPUNKNOWN)*ppv)->AddRef();
  62.         return NOERROR;
  63.         }
  64.  
  65.     return ResultFromScode(E_NOINTERFACE);
  66.     }
  67.  
  68.  
  69. STDMETHODIMP_(ULONG) CDropSource::AddRef(void)
  70.     {
  71.     return ++m_cRef;
  72.     }
  73.  
  74. STDMETHODIMP_(ULONG) CDropSource::Release(void)
  75.     {
  76.     if (0L!=--m_cRef)
  77.         return m_cRef;
  78.  
  79.     delete this;
  80.     return 0;
  81.     }
  82.  
  83.  
  84.  
  85.  
  86.  
  87. /*
  88.  * CDropSource::QueryDragContinue
  89.  *
  90.  * Purpose:
  91.  *  Determines whether to continue a drag operation or cancel it.
  92.  *
  93.  * Parameters:
  94.  *  fEsc            BOOL indicating that the ESC key was pressed.
  95.  *  grfKeyState     DWORD providing states of keys and mouse buttons
  96.  *
  97.  * Return Value:
  98.  *  HRESULT         DRAGDROP_S_CANCEL to stop the drag,
  99.  *                  DRAGDROP_S_DROP to drop the data where it is,
  100.  *                  or NOERROR to continue.
  101.  */
  102.  
  103. STDMETHODIMP CDropSource::QueryContinueDrag(BOOL fEsc
  104.     , DWORD grfKeyState)
  105.     {
  106.     if (fEsc)
  107.         return ResultFromScode(DRAGDROP_S_CANCEL);
  108.  
  109.     if (!(grfKeyState & MK_LBUTTON))
  110.         return ResultFromScode(DRAGDROP_S_DROP);
  111.  
  112.     return NOERROR;
  113.     }
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. /*
  121.  * CDropSource::GiveFeedback
  122.  *
  123.  * Purpose:
  124.  *  Provides cursor feedback to the user since the source task
  125.  *  always has the mouse capture.  We can also provide any other
  126.  *  type of feedback above cursors if we so desire.
  127.  *
  128.  * Parameters:
  129.  *  dwEffect        DWORD effect flags returned from the last target
  130.  *
  131.  * Return Value:
  132.  *  HRESULT         NOERROR if you set a cursor yourself or
  133.  *                  DRAGDROP_S_USEDEFAULTCURSORS to let OLE do
  134.  *                  the work.
  135.  */
  136.  
  137. STDMETHODIMP CDropSource::GiveFeedback(DWORD dwEffect)
  138.     {
  139.     return ResultFromScode(DRAGDROP_S_USEDEFAULTCURSORS);
  140.     }
  141.