IEShellDragDrop.cpp
上传用户:yatsl7111
上传日期:2007-01-08
资源大小:1433k
文件大小:5k
源码类别:

图形图象

开发平台:

Visual C++

  1. //*******************************************************************************
  2. // COPYRIGHT NOTES
  3. // ---------------
  4. // You may use this source code, compile or redistribute it as part of your application 
  5. // for free. You cannot redistribute it as a part of a software development 
  6. // library without the agreement of the author. If the sources are 
  7. // distributed along with the application, you should leave the original 
  8. // copyright notes in the source code without any changes.
  9. // This code can be used WITHOUT ANY WARRANTIES at your own risk.
  10. // 
  11. // For the latest updates to this code, check this site:
  12. // http://www.masmex.com 
  13. // after Sept 2000
  14. // 
  15. // Copyright(C) 2000 Philip Oldaker <email: philip@masmex.com>
  16. //*******************************************************************************
  17. #include "stdafx.h"
  18. #include "IEShellDragDrop.h"
  19. #include "cbformats.h"
  20. #ifndef OleStdGetDropEffect
  21. #define OleStdGetDropEffect(grfKeyState)    
  22.    ( (grfKeyState & MK_CONTROL) ?          
  23.       ( (grfKeyState & MK_SHIFT) ? DROPEFFECT_LINK : DROPEFFECT_COPY ) :  
  24.       ( (grfKeyState & MK_SHIFT) ? DROPEFFECT_MOVE : DROPEFFECT_NONE ) )
  25. #endif
  26. bool CIEShellDragDrop::DragEnter(CDD_OleDropTargetInfo *pInfo,LPSHELLFOLDER psfFolder,LPITEMIDLIST pidl)
  27. {
  28. // DWORD dwEffect = m_ShellPidl.GetDragDropAttributes(pInfo->GetDataObject()->m_lpDataObject);
  29. IDropTarget *pdt=NULL;
  30. if (psfFolder == NULL)
  31. psfFolder = m_psfDesktop;
  32.     HRESULT hr = psfFolder->GetUIObjectOf(pInfo->GetSafeHwnd(),1,(LPCITEMIDLIST*)&pidl, IID_IDropTarget, NULL, (LPVOID*)&pdt);
  33. if (FAILED(hr))
  34. return false;
  35. DWORD dwKeyState = pInfo->GetKeyboardState();
  36. CPoint pt(pInfo->GetPoint());
  37. ::ClientToScreen(pInfo->GetSafeHwnd(),&pt);
  38. POINTL ptl;
  39. ptl.x = pt.x;
  40. ptl.y = pt.y;
  41. DWORD dwEffect=0;
  42.     pdt->DragEnter(pInfo->GetDataObject()->m_lpDataObject, dwKeyState, ptl, &dwEffect);
  43. pdt->DragLeave();
  44. pInfo->SetDropEffect(dwEffect);
  45. pdt->Release();
  46. return true;
  47. }
  48. bool CIEShellDragDrop::DragLeave(CDD_OleDropTargetInfo *pInfo)
  49. {
  50. return false;
  51. }
  52. bool CIEShellDragDrop::DragOver(CDD_OleDropTargetInfo *pInfo,LPSHELLFOLDER psfFolder,LPITEMIDLIST pidl)
  53. {
  54. pInfo->SetDropEffect(DROPEFFECT_NONE);
  55. IDropTarget *pdt=NULL;
  56. if (psfFolder == NULL)
  57. psfFolder = m_psfDesktop;
  58.     HRESULT hr = psfFolder->GetUIObjectOf(pInfo->GetSafeHwnd(),1,(LPCITEMIDLIST*)&pidl, IID_IDropTarget, NULL, (LPVOID*)&pdt);
  59. if (FAILED(hr))
  60. return false;
  61. DWORD dwKeyState = pInfo->GetKeyboardState();
  62. TRACE1("dwKeyState=%un",dwKeyState);
  63. CPoint pt(pInfo->GetPoint());
  64. ::ClientToScreen(pInfo->GetSafeHwnd(),&pt);
  65. POINTL ptl;
  66. ptl.x = pt.x;
  67. ptl.y = pt.y;
  68. DWORD dwEffect=OleStdGetDropEffect(dwKeyState);
  69. if (dwEffect == DROPEFFECT_NONE)
  70. dwEffect = DROPEFFECT_MOVE | DROPEFFECT_COPY | DROPEFFECT_LINK;
  71. TRACE1("dropEffect=%un",dwEffect);
  72. pdt->DragEnter(pInfo->GetDataObject()->m_lpDataObject, dwKeyState, ptl, &dwEffect);
  73. pdt->DragOver(dwKeyState, ptl, &dwEffect);
  74. pdt->DragLeave();
  75. pdt->Release();
  76. pInfo->SetDropEffect(dwEffect);
  77. return true;
  78. }
  79. bool CIEShellDragDrop::DragDrop(CDD_OleDropTargetInfo *pInfo,LPSHELLFOLDER psfFolder,LPITEMIDLIST pidl)
  80. {
  81. IDropTarget *pdt=NULL;
  82. if (psfFolder == NULL)
  83. psfFolder = m_psfDesktop;
  84.     HRESULT hr = psfFolder->GetUIObjectOf(pInfo->GetSafeHwnd(),1,(LPCITEMIDLIST*)&pidl, IID_IDropTarget, NULL, (LPVOID*)&pdt);
  85. if (FAILED(hr))
  86. return false;
  87. CPoint pt(pInfo->GetPoint());
  88. TRACE2("Drop received at point(client) %d,%dn",pt.x,pt.y);
  89. ::ClientToScreen(pInfo->GetSafeHwnd(),&pt);
  90. TRACE2("Drop received at point(screen) %d,%dn",pt.x,pt.y);
  91. CWDClipboardData::Instance()->IsDataAvailable(pInfo->GetDataObject());
  92. #ifdef _DEBUG
  93. if (pInfo->GetDataObject()->IsDataAvailable(CF_TEXT))
  94. {
  95. CCF_String cfString;
  96. if (CWDClipboardData::Instance()->GetData(pInfo->GetDataObject(),&cfString,CWDClipboardData::e_cfString))
  97. {
  98. TRACE1("Received CF_TEXT %sn",cfString.GetString());
  99. }
  100. }
  101. if (pInfo->GetDataObject()->IsDataAvailable(CF_HDROP))
  102. {
  103. CCF_HDROP cfHDROP;
  104. if (CWDClipboardData::Instance()->GetData(pInfo->GetDataObject(),&cfHDROP,CWDClipboardData::e_cfHDROP))
  105. {
  106. for(UINT i=0;i < cfHDROP.GetCount();i++)
  107. TRACE2("Received CF_HDROP %s (%u)n",cfHDROP.GetFileName(i),i);
  108. }
  109. }
  110. #endif
  111. POINTL ptl;
  112. ptl.x = pt.x;
  113. ptl.y = pt.y;
  114. DWORD dwKeyState = pInfo->GetKeyboardState();
  115.     DWORD dw = DROPEFFECT_MOVE;
  116.     pdt->DragEnter(pInfo->GetDataObject()->m_lpDataObject, dwKeyState, ptl, &dw);
  117.     pdt->DragOver(dwKeyState, ptl, &dw);
  118. DWORD dwEffect = m_ShellPidl.GetDragDropAttributes(pInfo->GetDataObject());
  119. TRACE2("Keyboardstate=%u DragDropEffect=%un",dwKeyState,dwEffect);
  120.     pdt->Drop(pInfo->GetDataObject()->m_lpDataObject, dwKeyState, ptl, &dwEffect);
  121. pdt->Release();
  122. return true;
  123. }