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.

156 lines
3.4 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: SIMIDLST.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 7/28/1999
  12. *
  13. * DESCRIPTION: Simple PIDL Wrapper Class
  14. *
  15. *******************************************************************************/
  16. #ifndef __SIMIDLST_H_INCLUDED
  17. #define __SIMIDLST_H_INCLUDED
  18. #include <windows.h>
  19. #include <objbase.h>
  20. #include <shlobj.h>
  21. #include <shlobjp.h>
  22. #include <simstr.h>
  23. class CSimpleIdList
  24. {
  25. private:
  26. LPITEMIDLIST m_pIdl;
  27. public:
  28. CSimpleIdList(void)
  29. : m_pIdl(NULL)
  30. {
  31. }
  32. CSimpleIdList( PBYTE pData, UINT nSize )
  33. : m_pIdl(NULL)
  34. {
  35. m_pIdl = NULL;
  36. IMalloc *pMalloc = NULL;
  37. if (SUCCEEDED(SHGetMalloc(&pMalloc)))
  38. {
  39. m_pIdl = reinterpret_cast<LPITEMIDLIST>(pMalloc->Alloc( nSize ));
  40. if (m_pIdl)
  41. {
  42. CopyMemory( m_pIdl, pData, nSize );
  43. }
  44. pMalloc->Release();
  45. }
  46. }
  47. CSimpleIdList( LPCITEMIDLIST pIdl )
  48. : m_pIdl(NULL)
  49. {
  50. Assign(pIdl);
  51. }
  52. CSimpleIdList( const CSimpleIdList &other )
  53. : m_pIdl(NULL)
  54. {
  55. Assign(other.IdList());
  56. }
  57. CSimpleIdList( HWND hWnd, int nFolder )
  58. : m_pIdl(NULL)
  59. {
  60. GetSpecialFolder( hWnd, nFolder );
  61. }
  62. ~CSimpleIdList(void)
  63. {
  64. Destroy();
  65. }
  66. bool IsValid(void) const
  67. {
  68. return (m_pIdl != NULL);
  69. }
  70. CSimpleIdList &operator=( const CSimpleIdList &other )
  71. {
  72. if (this != &other)
  73. {
  74. Destroy();
  75. Assign(other.IdList());
  76. }
  77. return *this;
  78. }
  79. LPITEMIDLIST IdList(void)
  80. {
  81. return m_pIdl;
  82. }
  83. LPCITEMIDLIST IdList(void) const
  84. {
  85. return m_pIdl;
  86. }
  87. UINT Size(void) const
  88. {
  89. if (!IsValid())
  90. return 0;
  91. return ILGetSize(m_pIdl);
  92. }
  93. void Release(void)
  94. {
  95. m_pIdl = NULL;
  96. }
  97. CSimpleIdList &Assign( LPCITEMIDLIST pIdl )
  98. {
  99. if (pIdl != m_pIdl)
  100. {
  101. Destroy();
  102. if (pIdl)
  103. {
  104. m_pIdl = ILClone(pIdl);
  105. }
  106. }
  107. return *this;
  108. }
  109. void Destroy(void)
  110. {
  111. if (m_pIdl)
  112. {
  113. IMalloc *pMalloc = NULL;
  114. if (SUCCEEDED(SHGetMalloc(&pMalloc)))
  115. {
  116. pMalloc->Free( m_pIdl );
  117. pMalloc->Release();
  118. }
  119. m_pIdl = NULL;
  120. }
  121. }
  122. CSimpleIdList &GetSpecialFolder( HWND hWnd, int nFolder )
  123. {
  124. Destroy();
  125. if (S_OK!=SHGetSpecialFolderLocation(hWnd,nFolder,&m_pIdl))
  126. {
  127. // Make sure it is nuked
  128. Destroy();
  129. }
  130. return *this;
  131. }
  132. CSimpleString Name(void) const
  133. {
  134. CSimpleString strRet;
  135. if (IsValid())
  136. {
  137. TCHAR szPath[MAX_PATH];
  138. SHGetPathFromIDList( m_pIdl, szPath );
  139. strRet = szPath;
  140. }
  141. return strRet;
  142. }
  143. bool operator==( const CSimpleIdList &other )
  144. {
  145. return (Name() == other.Name());
  146. }
  147. bool operator!=( const CSimpleIdList &other )
  148. {
  149. return (Name() != other.Name());
  150. }
  151. };
  152. #endif // __SIMIDLST_H_INCLUDED