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 ();