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.

209 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. DfsShell.cpp
  5. Abstract:
  6. This is the implementation file for Dfs Shell Extension object which implements
  7. IShellIExtInit and IShellPropSheetExt.
  8. Author:
  9. Constancio Fernandes (ferns@qspl.stpp.soft.net) 12-Jan-1998
  10. Environment:
  11. NT only.
  12. */
  13. #include "stdafx.h"
  14. #include "DfsShlEx.h"
  15. #include "DfsShell.h"
  16. /*----------------------------------------------------------------------
  17. IShellExtInit Implementation.
  18. ------------------------------------------------------------------------*/
  19. STDMETHODIMP CDfsShell::Initialize
  20. (
  21. IN LPCITEMIDLIST pidlFolder, // Points to an ITEMIDLIST structure
  22. IN LPDATAOBJECT lpdobj, // Points to an IDataObject interface
  23. IN HKEY hkeyProgID // Registry key for the file object or folder type
  24. )
  25. {
  26. /*++
  27. Routine Description:
  28. Called by Shell when our extension is loaded.
  29. --*/
  30. STGMEDIUM medium;
  31. FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  32. // Fail the call if lpdobj is NULL.
  33. if (lpdobj == NULL)
  34. {
  35. return E_FAIL;
  36. }
  37. // Render the data referenced by the IDataObject pointer to an HGLOBAL
  38. // storage medium in CF_HDROP format.
  39. HRESULT hr = lpdobj->GetData (&fe, &medium);
  40. if (FAILED (hr))
  41. {
  42. return hr;
  43. }
  44. // If only one item is selected, retrieve the item name and store it in
  45. // m_lpszFile. Otherwise fail the call.
  46. if (DragQueryFile ((HDROP) medium.hGlobal, 0xFFFFFFFF, NULL, 0) == 1)
  47. {
  48. if (m_lpszFile)
  49. delete [] m_lpszFile;
  50. UINT uiChars = DragQueryFile ((HDROP) medium.hGlobal, 0, NULL, 0);
  51. m_lpszFile = new TCHAR [uiChars + 1];
  52. if (!m_lpszFile)
  53. {
  54. hr = E_OUTOFMEMORY;
  55. } else
  56. {
  57. ZeroMemory(m_lpszFile, sizeof(TCHAR) * (uiChars + 1));
  58. DragQueryFile ((HDROP) medium.hGlobal, 0, m_lpszFile, uiChars + 1);
  59. }
  60. }
  61. else
  62. {
  63. hr = E_FAIL;
  64. }
  65. ReleaseStgMedium (&medium);
  66. if (FAILED(hr))
  67. return hr;
  68. // Display hour glass.
  69. CWaitCursor WaitCursor;
  70. if (IsDfsPath(m_lpszFile, &m_lpszEntryPath, &m_ppDfsAlternates))
  71. {
  72. return S_OK;
  73. }
  74. else
  75. {
  76. if (NULL != m_lpszFile)
  77. {
  78. delete [] m_lpszFile;
  79. m_lpszFile = NULL;
  80. }
  81. return E_FAIL;
  82. }
  83. }
  84. STDMETHODIMP CDfsShell::AddPages
  85. (
  86. IN LPFNADDPROPSHEETPAGE lpfnAddPage,
  87. IN LPARAM lParam
  88. )
  89. /*++
  90. Routine Description:
  91. Called by the shell just before the property sheet is displayed.
  92. Arguments:
  93. lpfnAddPage - Pointer to the Shell's AddPage function
  94. lParam - Passed as second parameter to lpfnAddPage
  95. Return value:
  96. NOERROR in all cases. If for some reason our pages don't get added,
  97. the Shell still needs to bring up the Properties' sheet.
  98. --*/
  99. {
  100. BOOL bAddPage = TRUE;
  101. // check policy
  102. LONG lErr = ERROR_SUCCESS;
  103. HKEY hKey = 0;
  104. lErr = RegOpenKeyEx(
  105. HKEY_CURRENT_USER,
  106. _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\explorer"),
  107. 0,
  108. KEY_QUERY_VALUE,
  109. &hKey);
  110. if (ERROR_SUCCESS == lErr)
  111. {
  112. lErr = RegQueryValueEx(hKey, _T("NoDFSTab"), 0, NULL, NULL, NULL);
  113. if (ERROR_SUCCESS == lErr)
  114. bAddPage = FALSE; // data exist, do not add the Dfs tab
  115. RegCloseKey(hKey);
  116. }
  117. if (!bAddPage)
  118. return NOERROR;
  119. // Create the page for the replica set.
  120. // Pass it to the Callback
  121. HPROPSHEETPAGE h_proppage = m_psDfsShellExtProp.Create();
  122. if (!h_proppage)
  123. return E_OUTOFMEMORY;
  124. if (lpfnAddPage(h_proppage, lParam))
  125. {
  126. m_psDfsShellExtProp.put_DfsShellPtr((IShellPropSheetExt *)this);
  127. CComBSTR bstrDirPath = m_lpszFile;
  128. CComBSTR bstrEntryPath = m_lpszEntryPath;
  129. m_psDfsShellExtProp.put_DirPaths(bstrDirPath, bstrEntryPath);
  130. } else
  131. {
  132. // must call this function for pages that have not been added.
  133. DestroyPropertySheetPage(h_proppage);
  134. }
  135. return S_OK;
  136. }
  137. STDMETHODIMP CDfsShell::ReplacePage
  138. (
  139. IN UINT uPageID,
  140. IN LPFNADDPROPSHEETPAGE lpfnReplaceWith,
  141. IN LPARAM lParam
  142. )
  143. /*++
  144. Routine Description:
  145. Called by the shell only for Control Panel property sheet extensions
  146. Arguments:
  147. uPageID - ID of page to be replaced
  148. lpfnReplaceWith - Pointer to the Shell's Replace function
  149. lParam - Passed as second parameter to lpfnReplaceWith
  150. Return value:
  151. E_FAIL, since we don't support this function.
  152. --*/
  153. {
  154. return E_FAIL;
  155. }