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.

112 lines
2.7 KiB

  1. #include "priv.h"
  2. #include "infotip.h"
  3. #include "resource.h"
  4. #include <mluisupp.h>
  5. HRESULT ReadProp(IPropertyStorage *ppropstg, PROPID propid, PROPVARIANT *ppropvar)
  6. {
  7. PROPSPEC prspec = { PRSPEC_PROPID, propid };
  8. return ppropstg->ReadMultiple(1, &prspec, ppropvar);
  9. }
  10. STDAPI GetStringProp(IPropertyStorage *ppropstg, PROPID propid, LPTSTR pszBuf, DWORD cchBuf)
  11. {
  12. PROPVARIANT propvar;
  13. *pszBuf = 0;
  14. if (S_OK == ReadProp(ppropstg, propid, &propvar))
  15. {
  16. if (VT_LPWSTR == propvar.vt)
  17. {
  18. SHUnicodeToTChar(propvar.pwszVal, pszBuf, cchBuf);
  19. }
  20. else if (VT_LPSTR == propvar.vt)
  21. {
  22. SHAnsiToTChar(propvar.pszVal, pszBuf, cchBuf);
  23. }
  24. PropVariantClear(&propvar);
  25. }
  26. return *pszBuf ? S_OK : S_FALSE;
  27. }
  28. DWORD AppendTipText(LPTSTR pszBuf, int cchBuf, UINT ids, ...)
  29. {
  30. DWORD dwRet;
  31. TCHAR szFmt[64];
  32. va_list ArgList;
  33. if (ids == 0 || 0 == MLLoadString(ids, szFmt, SIZECHARS(szFmt)))
  34. {
  35. StringCchCopy(szFmt, ARRAYSIZE(szFmt), TEXT("%s%s"));
  36. }
  37. va_start(ArgList, ids);
  38. dwRet = wvnsprintf(pszBuf, cchBuf, szFmt, ArgList);
  39. va_end(ArgList);
  40. return dwRet;
  41. }
  42. STDAPI GetInfoTipFromStorage(IPropertySetStorage *ppropsetstg, const ITEM_PROP *pip, WCHAR **ppszTip)
  43. {
  44. TCHAR szTip[2048];
  45. LPTSTR psz = szTip;
  46. LPCTSTR pszCRLF = TEXT("");
  47. UINT cch, cchMac = SIZECHARS(szTip);
  48. const GUID *pfmtIdLast = NULL;
  49. IPropertyStorage *ppropstg = NULL;
  50. HRESULT hr = E_FAIL;
  51. *ppszTip = NULL;
  52. for (; pip->pfmtid; pip++)
  53. {
  54. // cache the last FMTID and reuse it if the next FMTID is the same
  55. if (!ppropstg || !IsEqualGUID(*pfmtIdLast, *pip->pfmtid))
  56. {
  57. if (ppropstg)
  58. {
  59. ppropstg->Release();
  60. ppropstg = NULL;
  61. }
  62. pfmtIdLast = pip->pfmtid;
  63. ppropsetstg->Open(*pip->pfmtid, STGM_READ | STGM_SHARE_EXCLUSIVE, &ppropstg);
  64. }
  65. if (ppropstg)
  66. {
  67. TCHAR szT[256];
  68. hr = pip->pfnRead(ppropstg, pip->idProp, szT, SIZECHARS(szT));
  69. if (S_OK == hr)
  70. {
  71. cch = AppendTipText(psz, cchMac, pip->idFmtString, pszCRLF, szT);
  72. psz += cch;
  73. cchMac -= cch;
  74. pszCRLF = TEXT("\r\n");
  75. }
  76. else if (hr != S_FALSE)
  77. {
  78. break; // error, exit for loop
  79. }
  80. }
  81. }
  82. if (ppropstg)
  83. ppropstg->Release();
  84. hr = S_FALSE; // assume no tooltip
  85. if (psz != szTip)
  86. {
  87. hr = SHStrDup(szTip, ppszTip);
  88. }
  89. return hr;
  90. }