如何獲得 window shell檔案夾縮圖

來源:互聯網
上載者:User


這個問題關係到 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 = GetMediaLibraryDefaultDir() + _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.length());    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();  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.