Leaked source code of windows server 2003
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.

218 lines
6.4 KiB

  1. #include "shellprv.h"
  2. #pragma hdrstop
  3. #include "fstreex.h"
  4. #include "idlcomm.h"
  5. // returns SHAlloc() (COM Task Allocator) memory
  6. LPTSTR SHGetCaption(HIDA hida)
  7. {
  8. UINT idFormat;
  9. LPTSTR pszCaption = NULL;
  10. LPITEMIDLIST pidl;
  11. switch (HIDA_GetCount(hida))
  12. {
  13. case 0:
  14. return NULL;
  15. case 1:
  16. idFormat = IDS_ONEFILEPROP;
  17. break;
  18. default:
  19. idFormat = IDS_MANYFILEPROP;
  20. break;
  21. }
  22. pidl = HIDA_ILClone(hida, 0);
  23. if (pidl)
  24. {
  25. TCHAR szName[MAX_PATH];
  26. if (SUCCEEDED(SHGetNameAndFlags(pidl, SHGDN_NORMAL, szName, ARRAYSIZE(szName), NULL)))
  27. {
  28. TCHAR szTemplate[40];
  29. UINT uLen = LoadString(HINST_THISDLL, idFormat, szTemplate, ARRAYSIZE(szTemplate)) + lstrlen(szName) + 1;
  30. pszCaption = SHAlloc(uLen * SIZEOF(TCHAR));
  31. if (pszCaption)
  32. {
  33. StringCchPrintf(pszCaption, uLen, szTemplate, (LPTSTR)szName);
  34. }
  35. }
  36. ILFree(pidl);
  37. }
  38. return pszCaption;
  39. }
  40. // This is not folder specific, and could be used for other background
  41. // properties handlers, since all it does is bind to the parent of a full pidl
  42. // and ask for properties
  43. STDAPI SHPropertiesForPidl(HWND hwndOwner, LPCITEMIDLIST pidlFull, LPCTSTR pszParams)
  44. {
  45. if (!SHRestricted(REST_NOVIEWCONTEXTMENU))
  46. {
  47. IContextMenu *pcm;
  48. HRESULT hr = SHGetUIObjectFromFullPIDL(pidlFull, hwndOwner, IID_PPV_ARG(IContextMenu, &pcm));
  49. if (SUCCEEDED(hr))
  50. {
  51. CHAR szParameters[MAX_PATH];
  52. CMINVOKECOMMANDINFOEX ici = {
  53. SIZEOF(CMINVOKECOMMANDINFOEX),
  54. 0L,
  55. hwndOwner,
  56. "properties",
  57. szParameters,
  58. NULL, SW_SHOWNORMAL
  59. };
  60. if (pszParams)
  61. SHUnicodeToAnsi(pszParams, szParameters, ARRAYSIZE(szParameters));
  62. else
  63. ici.lpParameters = NULL;
  64. ici.fMask |= CMIC_MASK_UNICODE;
  65. ici.lpVerbW = c_szProperties;
  66. ici.lpParametersW = pszParams;
  67. // record if shift or control was being held down
  68. SetICIKeyModifiers(&ici.fMask);
  69. hr = pcm->lpVtbl->InvokeCommand(pcm, (LPCMINVOKECOMMANDINFO)&ici);
  70. pcm->lpVtbl->Release(pcm);
  71. }
  72. return hr;
  73. }
  74. else
  75. return E_ACCESSDENIED;
  76. }
  77. BOOL _LoadErrMsg(UINT idErrMsg, LPTSTR pszErrMsg, size_t cchErrMsg, DWORD err)
  78. {
  79. TCHAR szTemplate[256];
  80. if (LoadString(HINST_THISDLL, idErrMsg, szTemplate, ARRAYSIZE(szTemplate)))
  81. {
  82. StringCchPrintf(pszErrMsg, cchErrMsg, szTemplate, err);
  83. return TRUE;
  84. }
  85. return FALSE;
  86. }
  87. BOOL _VarArgsFormatMessage( LPTSTR lpBuffer, UINT cchBuffer, DWORD err, ... )
  88. {
  89. BOOL fSuccess;
  90. va_list ArgList;
  91. va_start(ArgList, err);
  92. fSuccess = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  93. NULL, err, 0, lpBuffer, cchBuffer, &ArgList);
  94. va_end(ArgList);
  95. return fSuccess;
  96. }
  97. //
  98. // Paremeters:
  99. // hwndOwner -- owner window
  100. // idTemplate -- specifies template (e.g., "Can't open %2%s\n\n%1%s")
  101. // err -- specifies the WIN32 error code
  102. // pszParam -- specifies the 2nd parameter to idTemplate
  103. // dwFlags -- flags for MessageBox
  104. //
  105. STDAPI_(UINT) SHSysErrorMessageBox(HWND hwndOwner, LPCTSTR pszTitle, UINT idTemplate,
  106. DWORD err, LPCTSTR pszParam, UINT dwFlags)
  107. {
  108. BOOL fSuccess;
  109. UINT idRet = IDCANCEL;
  110. TCHAR szErrMsg[MAX_PATH * 2];
  111. //
  112. // FormatMessage is bogus, we don't know what to pass to it for %1,%2,%3,...
  113. // For most messages, lets pass the path as %1 and "" as everything else
  114. // For ERROR_MR_MID_NOT_FOUND (something nobody is ever supposed to see)
  115. // we will pass the path as %2 and everything else as "".
  116. //
  117. if (err == ERROR_MR_MID_NOT_FOUND)
  118. {
  119. fSuccess = _VarArgsFormatMessage(szErrMsg,ARRAYSIZE(szErrMsg),
  120. err,c_szNULL,pszParam,c_szNULL,c_szNULL,c_szNULL);
  121. }
  122. else
  123. {
  124. fSuccess = _VarArgsFormatMessage(szErrMsg,ARRAYSIZE(szErrMsg),
  125. err,pszParam,c_szNULL,c_szNULL,c_szNULL,c_szNULL);
  126. }
  127. if (fSuccess || _LoadErrMsg(IDS_ENUMERR_FSGENERIC, szErrMsg, ARRAYSIZE(szErrMsg), err))
  128. {
  129. if (idTemplate==IDS_SHLEXEC_ERROR && (pszParam == NULL || StrStr(szErrMsg, pszParam)))
  130. {
  131. idTemplate = IDS_SHLEXEC_ERROR2;
  132. }
  133. idRet = ShellMessageBox(HINST_THISDLL, hwndOwner,
  134. MAKEINTRESOURCE(idTemplate),
  135. pszTitle, dwFlags, szErrMsg, pszParam);
  136. }
  137. return idRet;
  138. }
  139. STDAPI_(UINT) SHEnumErrorMessageBox(HWND hwnd, UINT idTemplate, DWORD err, LPCTSTR pszParam, BOOL fNet, UINT dwFlags)
  140. {
  141. UINT idRet = IDCANCEL;
  142. TCHAR szErrMsg[MAX_PATH * 3];
  143. if (hwnd == NULL)
  144. return idRet;
  145. switch(err)
  146. {
  147. case WN_SUCCESS:
  148. case WN_CANCEL:
  149. return IDCANCEL; // Don't retry
  150. case ERROR_OUTOFMEMORY:
  151. return IDABORT; // Out of memory!
  152. }
  153. if (fNet)
  154. {
  155. TCHAR* pszMessageString;
  156. TCHAR szTitle[80];
  157. TCHAR szProvider[256]; // We don't use it.
  158. DWORD dwErrSize = ARRAYSIZE(szErrMsg); // (DavePl) I expect a cch here, but no docs, could be cb
  159. DWORD dwProvSize = ARRAYSIZE(szProvider);
  160. szErrMsg[0] = 0;
  161. MultinetGetErrorText(szErrMsg, &dwErrSize, szProvider, &dwProvSize);
  162. if (szErrMsg[0] == 0)
  163. _LoadErrMsg(IDS_ENUMERR_NETGENERIC, szErrMsg, ARRAYSIZE(szErrMsg), err);
  164. if (GetWindowText(hwnd, szTitle, ARRAYSIZE(szTitle)))
  165. {
  166. pszMessageString = ShellConstructMessageString(HINST_THISDLL, MAKEINTRESOURCE(idTemplate), szErrMsg, pszParam);
  167. if (pszMessageString)
  168. {
  169. idRet = SHMessageBoxHelp(hwnd, pszMessageString, szTitle, dwFlags, HRESULT_FROM_WIN32(err), NULL, 0);
  170. LocalFree(pszMessageString);
  171. }
  172. else
  173. {
  174. // Out of memory!
  175. return IDABORT;
  176. }
  177. }
  178. }
  179. else
  180. {
  181. idRet = SHSysErrorMessageBox(hwnd, NULL, idTemplate, err, pszParam, dwFlags);
  182. }
  183. return idRet;
  184. }