Folder.h
上传用户:hy_wanghao
上传日期:2007-01-08
资源大小:279k
文件大小:6k
源码类别:

Shell编程

开发平台:

Visual C++

  1. // Folder.h : Declaration of the CFolder
  2. //
  3. // Written by Bjarke Viksoe (bjarke@viksoe.dk)
  4. // Copyright (c) 2001 Bjarke Viksoe.
  5. //
  6. // This code may be used in compiled form in any way you desire. This
  7. // file may be redistributed by any means PROVIDING it is 
  8. // not sold for profit without the authors written consent, and 
  9. // providing that this notice and the authors name is included. 
  10. //
  11. // This file is provided "as is" with no expressed or implied warranty.
  12. // The author accepts no liability if it causes any damage to you or your
  13. // computer whatsoever. It's free, so don't hassle me about it.
  14. //
  15. // Beware of bugs.
  16. #ifndef __FOLDER_H_
  17. #define __FOLDER_H_
  18. #include "resource.h"       // main symbols
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CFolder
  21. class ATL_NO_VTABLE CFolder : 
  22.    public CComObjectRootEx<CComSingleThreadModel>,
  23.    public CComCoClass<CFolder, &CLSID_Folder>,
  24.    public IShellFolderImpl<CFolder, PIDLDATA>,
  25.    public IQueryInfo
  26. {
  27. public:
  28.    HRESULT FinalConstruct();
  29.    void FinalRelease();
  30. DECLARE_NOT_AGGREGATABLE(CFolder)
  31. DECLARE_PROTECT_FINAL_CONSTRUCT()
  32. BEGIN_COM_MAP(CFolder)
  33.    COM_INTERFACE_ENTRY_IID(IID_IShellFolder,IShellFolder)
  34.    COM_INTERFACE_ENTRY_IID(IID_IPersistFolder,IPersistFolder)
  35.    COM_INTERFACE_ENTRY_IID(IID_IQueryInfo,IQueryInfo)
  36.    COM_INTERFACE_ENTRY(IPersist)
  37. END_COM_MAP()
  38. // CFolder
  39. public:
  40.    static HRESULT WINAPI UpdateRegistry(BOOL bRegister);
  41. private:
  42.    static BOOL _FindAmigaDrive(LPTSTR pstrDevice);
  43.    static HRESULT _RegisterObject(CLSID clsid, UINT id, BOOL bRegister, _ATL_REGMAP_ENTRY *rm, LPCTSTR pstrDeviceName);
  44. // IShellFolder
  45. public:
  46.    STDMETHOD(CompareIDs)(LPARAM lParam, LPCITEMIDLIST, LPCITEMIDLIST);
  47.    STDMETHOD(GetDisplayNameOf)(LPCITEMIDLIST pidl, DWORD dwReserved, LPSTRRET lpName);
  48.    STDMETHOD(GetAttributesOf)(UINT, LPCITEMIDLIST*, LPDWORD rgfInOut);
  49.    STDMETHOD(EnumObjects)(HWND hWnd, DWORD dw, LPENUMIDLIST* ppRetVal);
  50.    STDMETHOD(BindToObject)(LPCITEMIDLIST pidl, LPBC, REFIID riid, LPVOID* ppvOut);
  51.    STDMETHOD(GetUIObjectOf)(HWND, UINT, LPCITEMIDLIST*, REFIID, LPUINT, LPVOID*);
  52.    STDMETHOD(CreateViewObject)(HWND hwndOwner, REFIID riid, LPVOID* ppvOut);
  53.    STDMETHOD(SetNameOf)(HWND, LPCITEMIDLIST, LPCOLESTR, DWORD, LPITEMIDLIST*);
  54. // IQueryInfo
  55. public:
  56.    STDMETHOD(GetInfoTip)(DWORD dwFlags,LPWSTR *ppwszTip);
  57.    STDMETHOD(GetInfoFlags)(DWORD *pdwFlags);
  58. // Implementation
  59. public:
  60.    HRESULT _CreateShellFolderView(LPVOID *ppvObj);
  61. public:
  62.    HRESULT _Init(LPCITEMIDLIST Master, LPCITEMIDLIST Custom, LPCITEMIDLIST pidl);
  63.    HRESULT _BindToObject(LPCITEMIDLIST pidl, CComObject<CFolder> **pFolder);
  64.    HRESULT _BindToParent(CComObject<CFolder> **pFolder);
  65. private:
  66.    LPITEMIDLIST _CreateItem(LPCTSTR pstrName, 
  67.                             LPCTSTR pstrComment,
  68.                             PIDLTYPE pidlType, 
  69.                             int DosType,
  70.                             DWORD dwSize, 
  71.                             SYSTEMTIME ftTime,
  72.                             DWORD dwAccess,
  73.                             DWORD dwEntryFlags);
  74.    void _AddFolderToEnum(CPidl &pidl, List *cell, DWORD dwFlags, DWORD dwEntryFlags);
  75.    void _AddDeletedToEnum(CPidl &pidl, List *cell, SECTNUM nDirSector, DWORD dwFlags, DWORD dwEntryFlags);
  76.    //
  77. public:
  78.    static short _CompareItems(short iColumn, LPCPIDLDATA pData1, LPCPIDLDATA pData2);
  79.    //
  80.    HRESULT _OpenAmigaDevice(LPCITEMIDLIST pidlPath, 
  81.                             BOOL bReadOnly, 
  82.                             LPCITEMIDLIST pidlStartFolder, 
  83.                             CAdfDevice &dev, 
  84.                             CAdfVolume &vol);
  85.    //
  86.    BOOL _IsDroppedPathSame(LPDATAOBJECT pDataObj);
  87.    BOOL _IsViewWindow(HWND hWnd);
  88.    BOOL _SendViewMessage(HWND hWnd, UINT iMsg, WPARAM wParam=0, LPARAM lParam=0);
  89.    HRESULT _DoDrop(LPDATAOBJECT pDataObject, DWORD dwDropEffect);
  90.    HRESULT _DoDrop_HDROP(HGLOBAL hMem, DWORD dwDropEffect);
  91.    HRESULT _DoDrop_FILEDESCRIPTOR(HGLOBAL hMem, IDataObject *pDataObject, DWORD dwDropEffect);
  92. public:
  93.    typedef enum {
  94.       FILEOP_CANCEL       = 1,
  95.       FILEOP_YESTOALL     = 2,
  96.       FILEOP_UNIQUENAME   = 4,
  97.       FILEOP_DONTTRUNCATE = 8,
  98.       FILEOP_SILENT       = 16,
  99.    };
  100.    HRESULT _MoveFile(LPCTSTR pstrSource, LPCTSTR pstrDestPath, LPCTSTR pstrDestName, LPDWORD pdwFileOpFlags);
  101.    HRESULT _CopyFile(LPCTSTR pstrSource, LPCTSTR pstrDestPath, LPCTSTR pstrDestName, LPDWORD pdwFileOpFlags);
  102.    HRESULT _CreateFolder(LPTSTR pstrDestName, LPDWORD pdwFileOpFlags);
  103.    HRESULT _RemoveDirectory(CAdfVolume &vol, LPCTSTR pstrPath);
  104.    HRESULT _DeleteFiles(LPCITEMIDLIST *pidls, UINT nCount);
  105.    HRESULT _UnDeleteFiles(LPCITEMIDLIST *pidls, UINT nCount);
  106.    HRESULT _RenameFile(LPCITEMIDLIST pidlOld, LPCITEMIDLIST pidlNew);
  107.    UINT _ConfirmDelete(LPCITEMIDLIST *pidls, UINT nCount, LPDWORD pdwFileOpFlags);
  108. private:
  109.    UINT _CheckFileCollision(CAdfVolume &vol, LPCTSTR pstrFileName, LPDWORD pdwCopyOpFlags, BOOL *pbIsDuplicate);
  110.    BOOL _CheckForDiskExchaustion(CAdfVolume &vol, DWORD dwFileSize, LPDWORD pdwFileOpFlags);
  111.    BOOL _FindUniqueFileName(CAdfVolume &vol, LPTSTR pstrName);
  112.    BOOL _ValidateFileName(LPTSTR pstrFileName, LPDWORD pdwFileOpFlags);
  113.    SYSTEMTIME _ConvertEntryTime(Entry *entry);
  114. // Attributes
  115. public:
  116.    CPidl m_pidlPath;
  117.    DWORD m_dwFolderID;
  118.    bool m_bErrorShown;
  119.    static DWORD m_dwShellAttributes;
  120. };
  121. // Specify which options the namespace supports
  122. __declspec(selectany) DWORD CFolder::m_dwShellAttributes = 
  123.    SFGAO_FOLDER | 
  124.    SFGAO_HASSUBFOLDER | 
  125.    SFGAO_FILESYSTEM | 
  126.    SFGAO_DROPTARGET | 
  127.    SFGAO_BROWSABLE;
  128. #endif //__FOLDER_H_