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 / chap13 / cosmo / dropsrc.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  3KB  |  139 lines

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