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 / idroptgt.cpp < prev    next >
C/C++ Source or Header  |  1996-05-21  |  4KB  |  187 lines

  1. /*
  2.  * IDROPTGT.CPP
  3.  *
  4.  * Template implementation of a DropTarget object.
  5.  *
  6.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  7.  *
  8.  * Kraig Brockschmidt, Microsoft
  9.  * Internet  :  kraigb@microsoft.com
  10.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  11.  */
  12.  
  13.  
  14. #include "idroptgt.h"
  15.  
  16.  
  17. /*
  18.  * CDropTarget::CDropTarget
  19.  * CDropTarget::~CDropTarget
  20.  *
  21.  * Constructor Parameters:
  22.  *  pBack           LPVOID back pointer to whatever we're related to.
  23.  */
  24.  
  25. CDropTarget::CDropTarget(LPVOID pBack)
  26.     {
  27.     m_cRef=0;
  28.     m_pBack=pBack;
  29.     return;
  30.     }
  31.  
  32.  
  33. CDropTarget::~CDropTarget(void)
  34.     {
  35.     return;
  36.     }
  37.  
  38.  
  39.  
  40.  
  41. /*
  42.  * CDropTarget::QueryInterface
  43.  * CDropTarget::AddRef
  44.  * CDropTarget::Release
  45.  *
  46.  * Purpose:
  47.  *  Non-delegating IUnknown members for CDropTarget.
  48.  */
  49.  
  50. STDMETHODIMP CDropTarget::QueryInterface(REFIID riid
  51.     , LPVOID *ppv)
  52.     {
  53.     *ppv=NULL;
  54.  
  55.     if (IID_IUnknown==riid || IID_IDropTarget==riid)
  56.         *ppv=(LPVOID)this;
  57.  
  58.     if (NULL!=*ppv)
  59.         {
  60.         ((LPUNKNOWN)*ppv)->AddRef();
  61.         return NOERROR;
  62.         }
  63.  
  64.     return ResultFromScode(E_NOINTERFACE);
  65.     }
  66.  
  67.  
  68. STDMETHODIMP_(ULONG) CDropTarget::AddRef(void)
  69.     {
  70.     return ++m_cRef;
  71.     }
  72.  
  73. STDMETHODIMP_(ULONG) CDropTarget::Release(void)
  74.     {
  75.     if (0L!=--m_cRef)
  76.         return m_cRef;
  77.  
  78.     delete this;
  79.     return 0;
  80.     }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. /*
  88.  * CDropTarget::DragEnter
  89.  *
  90.  * Purpose:
  91.  *  Indicates that data in a drag operation has been dragged over
  92.  *  our window that's a potential target.  We are to decide if it's
  93.  *  something in which we're interested.
  94.  *
  95.  * Parameters:
  96.  *  pIDataSource    LPDATAOBJECT providing the source data.
  97.  *  grfKeyState     DWORD flags: states of keys and mouse buttons.
  98.  *  pt              POINTL coordinates in the client space of
  99.  *                  the document.
  100.  *  pdwEffect       LPDWORD into which we'll place the appropriate
  101.  *                  effect flag for this point.
  102.  */
  103.  
  104. STDMETHODIMP CDropTarget::DragEnter(LPDATAOBJECT pIDataSource
  105.     , DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
  106.     {
  107.     *pdwEffect=DROPEFFECT_NONE;
  108.     return NOERROR;
  109.     }
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. /*
  117.  * CDropTarget::DragOver
  118.  *
  119.  * Purpose:
  120.  *  Indicates that the mouse was moved inside the window represented
  121.  *  by this drop target.  This happens on every WM_MOUSEMOVE, so
  122.  *  this function should be very efficient.
  123.  *
  124.  * Parameters:
  125.  *  grfKeyState     DWORD providing the current keyboard and
  126.  *                  mouse states
  127.  *  pt              POINTL where the mouse currently is.
  128.  *  pdwEffect       LPDWORD in which to store the effect flag
  129.  *                  for this point.
  130.  */
  131.  
  132. STDMETHODIMP CDropTarget::DragOver(DWORD grfKeyState, POINTL pt
  133.     , LPDWORD pdwEffect)
  134.     {
  135.     //Since we can always drop, we just return effect flags
  136.     *pdwEffect=DROPEFFECT_MOVE;
  137.  
  138.     if (grfKeyState & MK_CONTROL)
  139.         *pdwEffect=DROPEFFECT_COPY;
  140.  
  141.     return NOERROR;
  142.     }
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149. /*
  150.  * CDropTarget::DragLeave
  151.  *
  152.  * Purpose:
  153.  *  Informs the drop target that the operation has left its window.
  154.  *
  155.  * Parameters:
  156.  *  None
  157.  */
  158.  
  159. STDMETHODIMP CDropTarget::DragLeave(void)
  160.     {
  161.     return NOERROR;
  162.     }
  163.  
  164.  
  165.  
  166.  
  167.  
  168. /*
  169.  * CDropTarget::Drop
  170.  *
  171.  * Purpose:
  172.  *  Instructs the drop target to paste the data that was just now
  173.  *  dropped on it.
  174.  *
  175.  * Parameters:
  176.  *  pIDataSource    LPDATAOBJECT from which we'll paste.
  177.  *  grfKeyState     DWORD providing current keyboard/mouse state.
  178.  *  pt              POINTL at which the drop occurred.
  179.  *  pdwEffect       LPDWORD in which to store what you did.
  180.  */
  181.  
  182. STDMETHODIMP CDropTarget::Drop(LPDATAOBJECT pIDataSource
  183.     , DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
  184.     {
  185.     return NOERROR;
  186.     }
  187.