GRIDDROPTARGET.CPP
上传用户:asikq0571
上传日期:2014-07-12
资源大小:528k
文件大小:3k
源码类别:

Internet/IE编程

开发平台:

Visual C++

  1. // GridDropTarget.cpp : implementation file
  2. //
  3. // CGridDropTarget is an OLE drop target for CGridCtrl. All it does
  4. // is handle the drag and drop windows messages and pass them
  5. // directly onto the grid control.
  6. //
  7. // Written by Chris Maunder 
  8. //        mailto:chrismaunder@codeguru.com
  9. //
  10. // Copyright (c) 1998.
  11. #include "stdafx.h"
  12. #include "GridCtrl.h"
  13. #include "GridDropTarget.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CGridDropTarget
  21. CGridDropTarget::CGridDropTarget()
  22. {
  23.     m_pGridCtrl = NULL;
  24.     m_bRegistered = FALSE;
  25. }
  26. CGridDropTarget::~CGridDropTarget()
  27. {
  28. }
  29. // Overloaded Register() function performs the normal COleDropTarget::Register
  30. // but also serves to connect this COleDropTarget with the parent grid control,
  31. // where all drop messages will ultimately be forwarded.
  32. BOOL CGridDropTarget::Register(CGridCtrl *pGridCtrl)
  33. {
  34.     if (m_bRegistered) return FALSE;
  35.     ASSERT(pGridCtrl->IsKindOf(RUNTIME_CLASS(CGridCtrl)));
  36.     ASSERT(pGridCtrl);
  37.     if (!pGridCtrl || !pGridCtrl->IsKindOf(RUNTIME_CLASS(CGridCtrl)))
  38.         return FALSE;
  39.     m_pGridCtrl = pGridCtrl;
  40.     m_bRegistered = COleDropTarget::Register(pGridCtrl);
  41.     return m_bRegistered;
  42. }
  43. void CGridDropTarget::Revoke()
  44. {
  45.     m_bRegistered = FALSE;
  46.     COleDropTarget::Revoke();
  47. }
  48. BEGIN_MESSAGE_MAP(CGridDropTarget, COleDropTarget)
  49.     //{{AFX_MSG_MAP(CGridDropTarget)
  50.     //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CGridDropTarget message handlers
  54. DROPEFFECT CGridDropTarget::OnDragScroll(CWnd* pWnd, DWORD dwKeyState, CPoint /*point*/)
  55. {
  56. //    TRACE("In CGridDropTarget::OnDragScrolln");
  57.     if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  58.     {
  59.         if (dwKeyState & MK_CONTROL)
  60.             return DROPEFFECT_COPY;
  61.         else
  62.             return DROPEFFECT_MOVE;
  63.     } else
  64.         return DROPEFFECT_NONE;
  65. }
  66. DROPEFFECT CGridDropTarget::OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject, 
  67.                                         DWORD dwKeyState, CPoint point)
  68. {
  69.     TRACE(_T("In CGridDropTarget::OnDragEntern"));
  70.     ASSERT(m_pGridCtrl);
  71.     if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  72.         return m_pGridCtrl->OnDragEnter(pDataObject, dwKeyState, point);
  73.     else
  74.         return DROPEFFECT_NONE;
  75. }
  76. void CGridDropTarget::OnDragLeave(CWnd* pWnd)
  77. {
  78.     TRACE(_T("In CGridDropTarget::OnDragLeaven"));
  79.     ASSERT(m_pGridCtrl);
  80.     if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  81.         m_pGridCtrl->OnDragLeave();
  82. }
  83. DROPEFFECT CGridDropTarget::OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, 
  84.                                        DWORD dwKeyState, CPoint point)
  85. {
  86. //    TRACE("In CGridDropTarget::OnDragOvern");
  87.     ASSERT(m_pGridCtrl);
  88.     if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  89.         return m_pGridCtrl->OnDragOver(pDataObject, dwKeyState, point);
  90.     else
  91.         return DROPEFFECT_NONE;
  92. }
  93. BOOL CGridDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
  94.                              DROPEFFECT dropEffect, CPoint point)
  95. {
  96.     TRACE(_T("In CGridDropTarget::OnDropn"));
  97.     ASSERT(m_pGridCtrl);
  98.     if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  99.         return m_pGridCtrl->OnDrop(pDataObject, dropEffect, point);
  100.     else
  101.         return FALSE;
  102. }