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

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