如何获得 window shell文件夹缩略图


这个问题关系到 shell接口编程部分,一个比较令人纠结的问题时,不管操作那个部分的文件夹,都要从shell文件系统的root节点(Desktop)开始操作,直到找到你要的节点位置。概因树形结构表达有关。
不说了,直接上代码吧:

LPITEMIDLIST pidlItems = NULL, pidlURL = NULL, pidlWorkDir = NULL;      ULONG   ulParseLen = 0;     HRESULT hr;      TCHAR pszPath[MAX_PATH*2];      DWORD dwPriority = 0, dwFlags = IEIFLAG_SCREEN;      SIZE size = { dwWidth, dwHeight };      IExtractImage* peiURL = NULL;     // interface is used to request a thumbnail image from a Shell folder     IShellFolder* psfDesktop = NULL;      IShellFolder* psfWorkDir = NULL;      IMalloc*              pMalloc = NULL;
    TString TempTumbnail = GetMediaLibraryDefau< Dir() + _T(  "MLThumbnail.jpg"  );
    CImage myImage;
    TString wsDir,wsFile,wsTempFile; 
    BOOL bComInit = TRUE;     hr = CoInitialize( NULL );

    hr = SHGetMalloc( pMalloc );     hr = SHGetDesktopFolder(psfDesktop); 

    wsDir = LocalFile;     wsDir.erase(wsDir.find_last_of(_T(  '\\'  )) + 1, wsDir.len >h());     wsFile = LocalFile;     wsFile.erase(0, wsFile.find_last_of(_T(  '\\'  )) + 1);
     // get working directory      TCHAR m_wsBuffer[255];     _tcscpy_s(m_wsBuffer,wsDir.c_str());      // ParseDisplayName:Translates a file object's or folder's display name into an item identifier list.     hr = psfDesktop-ParseDisplayName(NULL, NULL, m_wsBuffer, ulParseLen, pidlWorkDir, NULL);      hr = psfDesktop-BindToObject(pidlWorkDir, NULL, IID_IShellFolder, (LPVOID*)psfWorkDir); 
    psfDesktop-Release();      psfDesktop = NULL;      pMalloc-Free(pidlWorkDir);      pidlWorkDir = NULL; 
     // retrieve link information      _tcscpy_s(m_wsBuffer,wsFile.c_str());      hr = psfWorkDir-ParseDisplayName(NULL, NULL, m_wsBuffer, ulParseLen, pidlURL, NULL); 
     // query IExtractImage      hr = psfWorkDir-GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*)pidlURL, IID_IExtractImage, NULL, (LPVOID*)peiURL); 
     // define thumbnail properties      hr = peiURL-GetLocation(pszPath, MAX_PATH*2, dwPriority, size, 16, dwFlags); 
     // generate thumbnail      HBITMAP  hThumbnail= NULL;     hr = peiURL-Extract(hThumbnail); 
     // clean-up IExtractImage      peiURL-Release();      peiURL = NULL; 
    myImage.Attach(hThumbnail);     myImage.Save(TempTumbnail.c_str());

     // free allocated structures       if  (peiURL != NULL) peiURL-Release();       if  (pidlURL != NULL) pMalloc-Free(pidlURL);       if  (pidlWorkDir != NULL) pMalloc-Free(pidlWorkDir);       if  (psfDesktop != NULL) psfDesktop-Release();       if  (psfWorkDir != NULL) psfWorkDir-Release();   
最新回复(0)
/jishuqtTrp8_2FtSQZAKjTwzzShDJ_2BUAOkaUnX9BpiR8AOaah0_3D4858475
8 简首页