view.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 6k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\
  2. //
  3. // view.cpp 
  4. //
  5. //   IShellView helper functions.  Cdf view uses the default IShellView and
  6. //   relies on a callback to supply specific information.
  7. //
  8. //   History:
  9. //
  10. //       3/20/97  edwardp   Created.
  11. //
  12. ////////////////////////////////////////////////////////////////////////////////
  13. //
  14. // Includes
  15. //
  16. #include "stdinc.h"
  17. #include "view.h"
  18. #include "cdfidl.h"
  19. #include "resource.h"
  20. #include <mluisupp.h>
  21. #include <shellp.h>     // SHCreateShellFolderViewEx
  22. //\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\
  23. //
  24. // *** CreateDefaultShellView ***
  25. //
  26. //
  27. // Description:
  28. //     Creates a shell implemented default IShellView object for the given
  29. //     folder.
  30. //
  31. // Parameters:
  32. //     [In]  pIShellFolder - The folder for which the default IShellView is
  33. //                           created.
  34. //     [In]  pidl          - The id list for the given folder.
  35. //     [Out] ppIShellView  - A pointer to receive the IShellView interface.
  36. //
  37. // Return:
  38. //     The result from the private shell function SHCreateShellFolderViewEx.
  39. //
  40. // Comments:
  41. //     The default IShellView object communicates with its associated folder
  42. //     via a callback function.
  43. //
  44. ////////////////////////////////////////////////////////////////////////////////
  45. HRESULT
  46. CreateDefaultShellView(
  47.     IShellFolder *pIShellFolder,
  48.     LPITEMIDLIST pidl,
  49.     IShellView** ppIShellView
  50. )
  51. {
  52.     ASSERT(pIShellFolder);
  53.     ASSERT(ppIShellView);
  54.     CSFV csfv;
  55.     csfv.cbSize      = sizeof(CSFV);
  56.     csfv.pshf        = pIShellFolder;
  57.     csfv.psvOuter    = NULL;
  58.     csfv.pidl        = pidl;
  59.     csfv.lEvents     = 0; //SHCNE_DELETE | SHCNE_CREATE;
  60.     csfv.pfnCallback = IShellViewCallback;
  61.     csfv.fvm         = (FOLDERVIEWMODE)0; // FVM_ICON, FVM_DETAILS, etc.
  62.     return SHCreateShellFolderViewEx(&csfv, ppIShellView);
  63. }
  64. //\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\
  65. //
  66. // *** IShellViewCallback ***
  67. //
  68. //
  69. // Description:
  70. //     The callback function used by the default ISHellView to request
  71. //     inforamtion.
  72. //
  73. // Parameters:
  74. //     [In]  pIShellViewOuter - Always NULL.
  75. //     [In]  pIShellFolder    - The folder associated with this view.
  76. //     [In]  hwnd             - The hwnd of the shell view.
  77. //     [In]  msg              - The callback message.
  78. //     [InOut] wParam         - Message specific parameter.
  79. //     [InOut] lParam         - Message specific parameter.
  80. //
  81. // Return:
  82. //
  83. //
  84. // Comments:
  85. //
  86. //
  87. ////////////////////////////////////////////////////////////////////////////////
  88. HRESULT
  89. CALLBACK IShellViewCallback(
  90.     IShellView* pIShellViewOuter,
  91.     IShellFolder* pIShellFolder,
  92.     HWND hwnd,
  93.     UINT msg,
  94.     WPARAM wParam,
  95.     LPARAM lParam
  96. )
  97. {
  98.     HRESULT hr;
  99.     switch (msg)
  100.     {
  101.     case DVM_GETDETAILSOF:
  102.         hr = IShellView_GetDetails((UINT)wParam, (PDETAILSINFO)lParam);
  103.         break;
  104.     //
  105.     // Background enumeration only works for default shell view.
  106.     //
  107.     //case SFVM_BACKGROUNDENUM:
  108.     //    hr = S_OK;
  109.     //    TraceMsg(TF_CDFENUM, "Enum Background thread callback tid:0x%x",
  110.     //             GetCurrentThreadId());
  111.     //    break;
  112.     
  113.     default:
  114.         hr = E_FAIL;
  115.         break;
  116.     }
  117.     return hr;
  118. }
  119. //\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\
  120. //
  121. // *** IShellView_GetDetails ***
  122. //
  123. //
  124. // Description:
  125. //     The IShellView callback DVM_GETDETAILSOF message handler.
  126. //
  127. // Parameters:
  128. //     [In]  nColumn    - The column for wich information is requested.
  129. //     [InOut] pDetails - For column headings the pidl param is NULL and the
  130. //                        columns format, width, and title are returned.  For
  131. //                        items the pidl member conatins the id list of the
  132. //                        requested item and the string value of the requested
  133. //                        item is returned.
  134. //
  135. // Return:
  136. //     S_OK if nColumn is supported.
  137. //     E_FAIL if nColumn is greater than the number of supported columns.
  138. //
  139. // Comments:
  140. //     The default shell view calls this function with successively higher
  141. //     column numbers until an E_FAIL is returned.
  142. //
  143. //     The first (0) column is the display name.
  144. //
  145. ////////////////////////////////////////////////////////////////////////////////
  146. HRESULT
  147. IShellView_GetDetails(
  148.     UINT nColumn,
  149.     PDETAILSINFO pDetails
  150. )
  151. {
  152.     //
  153.     // Column information.
  154.     //
  155.     #define     COLUMNS  (sizeof(aColumnInfo) / sizeof(aColumnInfo[0]))
  156.     static const struct _tagCOLUMNINFO
  157.     {
  158.         UINT   idsName;
  159.         UINT   cchWidth;
  160.         USHORT uFormat;
  161.     }
  162.     aColumnInfo[] = {
  163.                       {IDS_COLUMN_NAME, 50, LVCFMT_LEFT}
  164.                     };
  165.     
  166.     HRESULT hr;
  167.     if (nColumn < COLUMNS)
  168.     {
  169.         if (NULL != pDetails->pidl) {
  170.             //
  171.             // Get item information from the pidl.
  172.             //
  173.             switch (aColumnInfo[nColumn].idsName)
  174.             {
  175.             case IDS_COLUMN_NAME:
  176.                 //pDetails->str.uType = STRRET_CSTR;
  177.                 CDFIDL_GetDisplayName((PCDFITEMIDLIST)pDetails->pidl,
  178.                                       &pDetails->str);
  179.                 break;
  180.             }
  181.         }
  182.         else
  183.         {
  184.             //
  185.             // Get column heading information.
  186.             //
  187.             pDetails->fmt       = aColumnInfo[nColumn].uFormat;
  188.             pDetails->cxChar    = aColumnInfo[nColumn].cchWidth;
  189.             pDetails->str.uType = STRRET_CSTR;
  190.             //
  191.             // REVIEW:  Using MLLoadStringA.
  192.             //
  193.             
  194.             MLLoadStringA(aColumnInfo[nColumn].idsName,
  195.                           pDetails->str.cStr, sizeof(pDetails->str.cStr));
  196.         }
  197.         hr = S_OK;
  198.     }
  199.     else
  200.     {
  201.         hr = E_FAIL;
  202.     }
  203.     return hr;
  204. }