Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.1 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION
  4. *
  5. * TITLE: APDROPT.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 5/22/2001
  12. *
  13. * DESCRIPTION: Autoplay drop target
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include "apdropt.h"
  19. #include "wiadefui.h"
  20. #include "runwiz.h"
  21. CWiaAutoPlayDropTarget::CWiaAutoPlayDropTarget()
  22. : m_cRef(1)
  23. {
  24. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTarget::CWiaAutoPlayDropTarget"));
  25. DllAddRef();
  26. }
  27. CWiaAutoPlayDropTarget::~CWiaAutoPlayDropTarget()
  28. {
  29. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTarget::~CWiaAutoPlayDropTarget"));
  30. DllRelease();
  31. }
  32. STDMETHODIMP_(ULONG) CWiaAutoPlayDropTarget::AddRef()
  33. {
  34. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTarget::AddRef"));
  35. return InterlockedIncrement(&m_cRef);
  36. }
  37. STDMETHODIMP_(ULONG) CWiaAutoPlayDropTarget::Release()
  38. {
  39. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTarget::Release"));
  40. LONG nRefCount = InterlockedDecrement(&m_cRef);
  41. if (!nRefCount)
  42. {
  43. delete this;
  44. }
  45. return nRefCount;
  46. }
  47. HRESULT CWiaAutoPlayDropTarget::QueryInterface( REFIID riid, void **ppvObject )
  48. {
  49. WIA_PUSHFUNCTION(TEXT("CWiaAutoPlayDropTarget::QueryInterface"));
  50. if (IsEqualIID( riid, IID_IUnknown ))
  51. {
  52. *ppvObject = static_cast<IDropTarget*>(this);
  53. }
  54. else if (IsEqualIID( riid, IID_IDropTarget ))
  55. {
  56. *ppvObject = static_cast<IDropTarget*>(this);
  57. }
  58. else
  59. {
  60. *ppvObject = NULL;
  61. return (E_NOINTERFACE);
  62. }
  63. reinterpret_cast<IUnknown*>(*ppvObject)->AddRef();
  64. return(S_OK);
  65. }
  66. HRESULT CWiaAutoPlayDropTarget::DragEnter(IDataObject *pdtobj, DWORD grfKeyState, POINTL ptl, DWORD *pdwEffect)
  67. {
  68. *pdwEffect = DROPEFFECT_COPY;
  69. return S_OK;
  70. }
  71. HRESULT CWiaAutoPlayDropTarget::DragOver(DWORD grfKeyState, POINTL ptl, DWORD *pdwEffect)
  72. {
  73. *pdwEffect = DROPEFFECT_COPY;
  74. return S_OK;
  75. }
  76. HRESULT CWiaAutoPlayDropTarget::DragLeave(void)
  77. {
  78. return S_OK;
  79. }
  80. HRESULT GetPathFromDataObject( IDataObject *pdtobj, LPTSTR pszPath, UINT cchPath )
  81. {
  82. FORMATETC fmte = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  83. STGMEDIUM medium = {0};
  84. HRESULT hr = pdtobj->GetData(&fmte, &medium);
  85. if (SUCCEEDED(hr))
  86. {
  87. if (DragQueryFile((HDROP)medium.hGlobal, 0, pszPath, cchPath))
  88. hr = S_OK;
  89. else
  90. hr = E_FAIL;
  91. ReleaseStgMedium(&medium);
  92. }
  93. return hr;
  94. }
  95. //
  96. // Here�s the meat of the change
  97. //
  98. HRESULT CWiaAutoPlayDropTarget::Drop( IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect )
  99. {
  100. WCHAR szDrive[4] = {0};
  101. HRESULT hr = GetPathFromDataObject( pdtobj, szDrive, ARRAYSIZE(szDrive) );
  102. *pdwEffect = DROPEFFECT_COPY;
  103. if (SUCCEEDED(hr))
  104. {
  105. WIA_TRACE((TEXT("szDrive: %ws")));
  106. WCHAR szDeviceID[MAX_PATH + 2] = {0};
  107. wnsprintf(szDeviceID, ARRAYSIZE(szDeviceID), TEXT("{%wc:\\}"), szDrive[0] );
  108. hr = RunWiaWizard::RunWizard( szDeviceID );
  109. }
  110. return hr;
  111. }