How to obtain window shell folder thumbnails

Source: Internet
Author: User


This problem is related to the shell Interface Programming part. When a complicated problem occurs, no matter which part of the folder is operated, the Operation should start from the root node (Desktop) of the shell file system, until you find the desired node location. It is related to the tree structure expression. If you don't want to talk about it, go directly to the Code:


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 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 = getmedialibrarydefadir Dir () + _ T ("MLThumbnail.jpg ");
CImage myImage;
TString wsDir, wsFile, wsTempFile;
BOOL bComInit = TRUE; hr = CoInitialize (NULL );

Hr = SHGetMalloc (& pMalloc); hr = shget1_topfolder (& 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 ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.