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.

116 lines
3.1 KiB

  1. #include "precomp.hxx"
  2. #pragma hdrstop
  3. #include "util.h"
  4. #include "dll.h"
  5. #include "resource.h"
  6. class CMyDocsCopyHook : public ICopyHook
  7. {
  8. public:
  9. CMyDocsCopyHook();
  10. // IUnknown
  11. STDMETHOD(QueryInterface)(REFIID riid, void **ppv);
  12. STDMETHOD_(ULONG, AddRef)();
  13. STDMETHOD_(ULONG, Release)();
  14. // ICopyHook
  15. STDMETHOD_(UINT,CopyCallback)(HWND hwnd, UINT wFunc, UINT wFlags,
  16. LPCTSTR pszSrcFile, DWORD dwSrcAttribs,
  17. LPCTSTR pszDestFile, DWORD dwDestAttribs);
  18. private:
  19. ~CMyDocsCopyHook();
  20. LONG _cRef;
  21. };
  22. STDMETHODIMP CMyDocsCopyHook::QueryInterface(REFIID riid, void **ppv)
  23. {
  24. static const QITAB qit[] = {
  25. QITABENT(CMyDocsCopyHook, ICopyHook), // IID_ICopyHook
  26. { 0 },
  27. };
  28. return QISearch(this, qit, riid, ppv);
  29. }
  30. STDMETHODIMP_ (ULONG) CMyDocsCopyHook::AddRef()
  31. {
  32. return InterlockedIncrement(&_cRef);
  33. }
  34. STDMETHODIMP_ (ULONG) CMyDocsCopyHook::Release()
  35. {
  36. if (InterlockedDecrement(&_cRef))
  37. return _cRef;
  38. delete this;
  39. return 0;
  40. }
  41. CMyDocsCopyHook::CMyDocsCopyHook() : _cRef(1)
  42. {
  43. DllAddRef();
  44. }
  45. CMyDocsCopyHook::~CMyDocsCopyHook()
  46. {
  47. DllRelease();
  48. }
  49. // ICopyHook methods
  50. UINT CMyDocsCopyHook::CopyCallback(HWND hwnd, UINT wFunc, UINT wFlags,
  51. LPCTSTR pszSrcFile, DWORD dwSrcAttribs,
  52. LPCTSTR pszDestFile, DWORD dwDestAttribs)
  53. {
  54. UINT uRes = IDYES;
  55. if ((wFunc == FO_COPY) || (wFunc == FO_MOVE))
  56. {
  57. TCHAR szPersonal[MAX_PATH];
  58. if (S_OK == SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_DONT_VERIFY, NULL, SHGFP_TYPE_CURRENT, szPersonal) &&
  59. lstrcmpi(pszSrcFile, szPersonal) == 0)
  60. {
  61. // the source is the personal directory, now check if the
  62. // destination is on the desktop...
  63. DWORD dwRes = IsPathGoodMyDocsPath(hwnd, pszDestFile);
  64. if (dwRes == PATH_IS_NONEXISTENT)
  65. {
  66. lstrcpyn(szPersonal, pszDestFile, ARRAYSIZE(szPersonal));
  67. if (PathRemoveFileSpec(szPersonal))
  68. {
  69. dwRes = IsPathGoodMyDocsPath(hwnd, szPersonal);
  70. }
  71. }
  72. if (dwRes == PATH_IS_DESKTOP)
  73. {
  74. // keep the user from moving the personal folder to the desktop
  75. TCHAR szVerb[ 32 ];
  76. LoadString(g_hInstance, (wFunc == FO_COPY) ? IDS_COPY : IDS_MOVE, szVerb, ARRAYSIZE(szVerb));
  77. uRes = IDNO;
  78. GetFolderDisplayName(CSIDL_PERSONAL, szPersonal, ARRAYSIZE(szPersonal));
  79. ShellMessageBox(g_hInstance, hwnd,
  80. (LPTSTR)IDS_NODRAG_DESKTOP_NOT_HIDDEN, szPersonal,
  81. MB_OK | MB_ICONSTOP, szPersonal, szVerb);
  82. }
  83. }
  84. }
  85. return uRes;
  86. }
  87. HRESULT CMyDocsCopyHook_CreateInstance(IUnknown *punkOuter, IUnknown **ppunk, LPCOBJECTINFO poi)
  88. {
  89. CMyDocsCopyHook * pMDCH = new CMyDocsCopyHook();
  90. if (pMDCH)
  91. {
  92. *ppunk = SAFECAST(pMDCH, ICopyHook*);
  93. return S_OK;
  94. }
  95. *ppunk = NULL;
  96. return E_OUTOFMEMORY;
  97. }