home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / oleview / view.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.5 KB  |  136 lines

  1. // view.cpp
  2. //
  3.  
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1998 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. // Implements CDropTargetView which is an override of CView with appropriate
  15. // COleDropTarget support.
  16. //
  17. // CDropTargetView, CObjTreeView, and CInterfaceView all are derived from this class
  18. //
  19.  
  20. // This class is never used.....but it is interesting
  21.  
  22. #include "stdafx.h"
  23. #include "OleView.h"
  24.  
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char BASED_CODE THIS_FILE[] = __FILE__;
  28. #endif
  29.  
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CDropTargetView
  32.  
  33. IMPLEMENT_DYNAMIC(CDropTargetView, CView)
  34.  
  35. BEGIN_MESSAGE_MAP(CDropTargetView, CView)
  36.     //{{AFX_MSG_MAP(CDropTargetView)
  37.     ON_WM_CREATE()
  38.     //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CDropTargetView construction/destruction
  43.  
  44. CDropTargetView::CDropTargetView()
  45. {
  46. }
  47.  
  48. int CDropTargetView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  49. {
  50.     if (CView::OnCreate(lpCreateStruct) == -1)
  51.         return -1;
  52. #if _MFC_VER > 0x0210
  53.     m_dropTarget.Register( this ) ;
  54. #endif
  55.     return 0;
  56. }
  57.  
  58. #if _MFC_VER > 0x0210
  59. DROPEFFECT CDropTargetView::OnDragEnter(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
  60. {
  61.     return OnDragOver(pDataObject, dwKeyState, point);
  62. }
  63.  
  64.  
  65. DROPEFFECT CDropTargetView::OnDragOver(COleDataObject*, DWORD dwKeyState, CPoint)
  66. {
  67.     DROPEFFECT de = DROPEFFECT_NONE;
  68.  
  69.     // check for force link
  70.     if ((dwKeyState & (MK_CONTROL|MK_SHIFT)) == (MK_CONTROL|MK_SHIFT))
  71.         de = DROPEFFECT_LINK;
  72.     // check for force copy
  73.     else if ((dwKeyState & MK_CONTROL) == MK_CONTROL)
  74.         de = DROPEFFECT_COPY;
  75.     // check for force move
  76.     else if ((dwKeyState & MK_ALT) == MK_ALT)
  77.         de = DROPEFFECT_MOVE;
  78.     // default -- recommended action is move
  79.     else
  80.         de = DROPEFFECT_MOVE;
  81.  
  82.     return de;
  83. }
  84.  
  85. void CDropTargetView::OnDragLeave()
  86. {
  87.     CView::OnDragLeave() ;
  88. }
  89.  
  90. BOOL CDropTargetView::OnDrop(COleDataObject* pDataObject,DROPEFFECT dropEffect, CPoint point)
  91. {
  92. /*
  93.     LPDATAOBJECT    pDO = pDataObject->m_lpDataObject ;
  94.  
  95.     pDO->AddRef() ;
  96.     IDisplayInterface( theApp.m_pMainWnd->GetSafeHwnd(),
  97.                        pDO,
  98.                        (LPIID)&IID_IDataObject,
  99.                        (LPTSTR)(LPCSTR)"Drag and Drop data object" ) ;
  100.     pDO->Release() ;
  101. */
  102.  
  103.     COle2ViewDoc*   pDoc = GetDocument() ;
  104.  
  105. #if 0
  106.     pDoc->m_clsidCur = CLSID_NULL ;
  107.  
  108.     HRESULT hr = pDataObject->m_lpDataObject->QueryInterface( IID_IUnknown, (LPVOID*)&pDoc->m_pIUnknown );
  109.     if (FAILED(hr))
  110.     {
  111.         ErrorMessage( _T("QueryInterface( IID_IUnknown ) failed on the data object."), hr ) ;
  112.         pDoc->m_pIUnknown = NULL ;
  113.     }
  114.  
  115.     pDoc->m_pIUnknown->AddRef() ;
  116.  
  117.     pDoc->m_fTypeLib = FALSE ;
  118.     ((CMainFrame*)theApp.m_pMainWnd)->m_pObjListView->m_lb.SetCurSel( -1 ) ;
  119.     pDoc->m_szObjectCur = "Drag and Drop data object" ;
  120.     pDoc->UpdateAllViews( NULL, UPD_NOOBJECTVIEW | UPD_NORELOAD ) ;
  121.  
  122. #endif
  123.  
  124.     return CView::OnDrop( pDataObject, dropEffect, point ) ;
  125. }
  126. #endif
  127. #ifdef _DEBUG
  128.  
  129. COle2ViewDoc* CDropTargetView::GetDocument() // non-debug version is inline
  130. {
  131.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COle2ViewDoc)));
  132.     return (COle2ViewDoc*) m_pDocument;
  133. }
  134.  
  135. #endif //_DEBUG
  136.