HRESULT CFShellUtil::GetItemIdName( LPCITEMIDLIST pItemIdList, LPTSTR pFriendlyName, UINT cchBuf, DWORD dwFlags, IShellFolder* pSF ) { HRESULT hr = S_OK; STRRET strRet = {0}; IShellFolder* pShellFolder = pSF; if ( pShellFolder == NULL ) { COM_VERIFY(SHGetDesktopFolder( &pShellFolder )); if ( !pShellFolder ) { return hr; } } COM_VERIFY(pShellFolder->GetDisplayNameOf( pItemIdList, dwFlags, &strRet)); if (SUCCEEDED(hr)) { COM_VERIFY(StrRetToBuf( &strRet, pItemIdList, pFriendlyName, cchBuf)); } if ( NULL == pSF ) { pShellFolder->Release(); pShellFolder = NULL; } return hr; }
HRESULT CFShellUtil::GetItemIDListFromPath(LPCTSTR szFullPath, LPITEMIDLIST* ppidl, IShellFolder* pSF) { HRESULT hr = E_FAIL; IShellFolder* pShellFolder = pSF; if ( pShellFolder == NULL ) { COM_VERIFY(SHGetDesktopFolder( &pShellFolder )); if ( !pShellFolder ) { return hr; } } ULONG chEaten = 0; DWORD dwAttributes = SFGAO_COMPRESSED; OLECHAR olePath[MAX_PATH] = { '\0' }; #ifdef UNICODE StringCchCopy( olePath, MAX_PATH, szFullPath ); #else MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szFileName, -1, olePath, MAX_PATH ); #endif //LPWSTR pszNPath = (LPWSTR)conv.TCHAR_TO_UTF16(szFullPath); COM_VERIFY(pShellFolder->ParseDisplayName(NULL, NULL, olePath, &chEaten, ppidl, &dwAttributes)); if ( NULL == pSF ) { pShellFolder->Release(); pShellFolder = NULL; } return hr; }
std::wstring OsShell::toolTip(std::wstring itemPath) { ComInitializer comInitializer; std::replace(itemPath.begin(), itemPath.end(), '/', '\\'); std::wstring tipString; ITEMIDLIST * id = 0; HRESULT result = SHParseDisplayName(itemPath.c_str(), 0, &id, 0, 0); if (!SUCCEEDED(result) || !id) return tipString; CItemIdListReleaser idReleaser (id); LPCITEMIDLIST child = 0; IShellFolder * ifolder = 0; result = SHBindToParent(id, IID_IShellFolder, (void**)&ifolder, &child); if (!SUCCEEDED(result) || !child) return tipString; IQueryInfo* iQueryInfo = 0; if (SUCCEEDED(ifolder->GetUIObjectOf(NULL, 1, &child, IID_IQueryInfo, 0, (void**)&iQueryInfo)) && iQueryInfo) { LPWSTR lpszTip = 0; CComInterfaceReleaser releaser (iQueryInfo); if (SUCCEEDED(iQueryInfo->GetInfoTip(0, &lpszTip)) && lpszTip) { tipString = lpszTip; CoTaskMemFree(lpszTip); } } std::replace(tipString.begin(), tipString.end(), '\r', '\n'); return tipString; }
HRESULT GetIdlFromParsingName(const TCHAR *szParsingName,LPITEMIDLIST *pidl) { if(szParsingName == NULL || pidl == NULL) { return E_FAIL; } IShellFolder *pDesktopFolder = NULL; HRESULT hr; hr = SHGetDesktopFolder(&pDesktopFolder); if(SUCCEEDED(hr)) { /* For some reason, ParseDisplayName takes a pointer to a non-constant string, so copy the incoming string. */ TCHAR szParsingNameTemp[MAX_PATH]; StringCchCopy(szParsingNameTemp, SIZEOF_ARRAY(szParsingNameTemp), szParsingName); hr = pDesktopFolder->ParseDisplayName(NULL,NULL, szParsingNameTemp,NULL,pidl,NULL); pDesktopFolder->Release(); } return hr; }
void CRecBinViewer::ContextMenu (CView* pView, CSelRowArray &ar, CPoint &pt) { CShellContextMenu scm; IShellFolder*psfRecycle = NULL; IShellFolder* psfDesktop = NULL; SHGetDesktopFolder (&psfDesktop); LPITEMIDLIST pidl = NULL; SHGetSpecialFolderLocation (NULL, CSIDL_BITBUCKET, &pidl); psfDesktop->BindToObject(pidl, NULL, IID_IShellFolder, (LPVOID *)&psfRecycle); LPITEMIDLIST *pidlArray = (LPITEMIDLIST *) malloc (ar.size () * sizeof (LPITEMIDLIST)); for (unsigned int i = 0 ; i < ar.size () ; i++) pidlArray[i] = m_List[ar[i].m_nRow-1].m_PIDL; scm.SetObjects (psfRecycle, pidlArray, ar.size ()); free (pidlArray); psfDesktop->Release (); scm.ShowContextMenu (pView, pt); if (psfRecycle) psfRecycle->Release (); }
/* * Class: sun_awt_shell_Win32ShellFolder2 * Method: parseDisplayName0 * Signature: (JLjava/lang/String;)J */ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_parseDisplayName0 (JNIEnv* env, jclass cls, jlong jpIShellFolder, jstring jname) { // Get desktop IShellFolder interface IShellFolder* pIShellFolder = (IShellFolder*)jpIShellFolder; if (pIShellFolder == NULL) { JNU_ThrowInternalError(env, "Desktop shell folder missing"); return 0; } // Get relative PIDL for name LPITEMIDLIST pIDL; int nLength = env->GetStringLength(jname); const jchar* strPath = env->GetStringChars(jname, NULL); JNU_CHECK_EXCEPTION_RETURN(env, 0); jchar* wszPath = new jchar[nLength + 1]; wcsncpy(reinterpret_cast<LPWSTR>(wszPath), reinterpret_cast<LPCWSTR>(strPath), nLength); wszPath[nLength] = 0; HRESULT res = pIShellFolder->ParseDisplayName(NULL, NULL, reinterpret_cast<LPWSTR>(wszPath), NULL, &pIDL, NULL); if (res != S_OK) { JNU_ThrowIOException(env, "Could not parse name"); pIDL = 0; } delete[] wszPath; env->ReleaseStringChars(jname, strPath); return (jlong)pIDL; }
HRESULT Entry::do_context_menu(HWND hwnd, const POINT& pos, CtxMenuInterfaces& cm_ifs) { ShellPath shell_path = create_absolute_pidl(); LPCITEMIDLIST pidl_abs = shell_path; if (!pidl_abs) return S_FALSE; // no action for registry entries, etc. #ifdef USE_MY_SHBINDTOPARENT IShellFolder* parentFolder; LPCITEMIDLIST pidlLast; // get and use the parent folder to display correct context menu in all cases -> correct "Properties" dialog for directories, ... HRESULT hr = my_SHBindToParent(pidl_abs, IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast); if (SUCCEEDED(hr)) { hr = ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pos.x, pos.y, cm_ifs); parentFolder->Release(); } return hr; #else static DynamicFct<HRESULT(WINAPI*)(LPCITEMIDLIST, REFIID, LPVOID*, LPCITEMIDLIST*)> SHBindToParent(TEXT("SHELL32"), "SHBindToParent"); if (SHBindToParent) { IShellFolder* parentFolder; LPCITEMIDLIST pidlLast; // get and use the parent folder to display correct context menu in all cases -> correct "Properties" dialog for directories, ... HRESULT hr = (*SHBindToParent)(pidl_abs, IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast); if (SUCCEEDED(hr)) { hr = ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pos.x, pos.y, cm_ifs); parentFolder->Release(); } return hr; } else { /**@todo use parent folder instead of desktop folder Entry* dir = _up; ShellPath parent_path; if (dir) parent_path = dir->create_absolute_pidl(); else parent_path = DesktopFolderPath(); ShellPath shell_path = create_relative_pidl(parent_path); LPCITEMIDLIST pidl = shell_path; ShellFolder parent_folder = parent_path; return ShellFolderContextMenu(parent_folder, hwnd, 1, &pidl, pos.x, pos.y); */ return ShellFolderContextMenu(GetDesktopFolder(), hwnd, 1, &pidl_abs, pos.x, pos.y, cm_ifs); } #endif }
static void ShowItemInFolder(const Path& fullPath) { if( !ShellOpenFolderSelectItems ) { ShellExecuteA(NULL, "open", fullPath.c_str(), NULL, NULL, SW_SHOW); return; } IShellFolder* desktop; HRESULT hr = SHGetDesktopFolder(&desktop); if( hr != S_OK ) return; ITEMIDLIST> dir_item; hr = desktop->ParseDisplayName(NULL, NULL, const_cast<wchar_t *>(dir.value().c_str()), NULL, &dir_item, NULL); desktop->Release(); IDLIST_ABSOLUTE abs; if( ShellOpenFolderSelectItems() != S_OK ) { LogError("Could not open and select the items in the shell"); return; } }
void CRecBinViewer::Properties (CSelRowArray &ar) { CShellContextMenu scm; IShellFolder*psfRecycle = NULL; IShellFolder* psfDesktop = NULL; SHGetDesktopFolder (&psfDesktop); LPITEMIDLIST pidl = NULL; SHGetSpecialFolderLocation (NULL, CSIDL_BITBUCKET, &pidl); psfDesktop->BindToObject(pidl, NULL, IID_IShellFolder, (LPVOID *)&psfRecycle); LPITEMIDLIST *pidlArray = (LPITEMIDLIST *) malloc (ar.size () * sizeof (LPITEMIDLIST)); for (int i = 0 ; i < static_cast<int>(ar.size()) ; i++) pidlArray[i] = m_List[ar[i].m_nRow-1].m_PIDL; scm.SetObjects (psfRecycle, pidlArray, ar.size ()); free (pidlArray); psfDesktop->Release (); scm.InvokeCommand (_T("properties")); if (psfRecycle) psfRecycle->Release (); }
CString ShellIO::PIDLToString(LPITEMIDLIST pIdl, LPITEMIDLIST pParentIdl, SHGDNF flags) { IShellFolder *desktopFolder; IShellFolder2 *shellFolder = NULL; STRRET strRet; HRESULT hRes; hRes = SHGetDesktopFolder(&desktopFolder); if(FAILED(hRes)) { return L""; } if(pParentIdl) { desktopFolder->BindToObject((PCUIDLIST_RELATIVE)pParentIdl, NULL, IID_IShellFolder, (void**)&shellFolder); } if(shellFolder == NULL) { shellFolder = (IShellFolder2*)desktopFolder; } hRes = shellFolder->GetDisplayNameOf((PCUITEMID_CHILD)pIdl, flags, &strRet); if(FAILED(hRes)) { return L""; } return strRet.pOleStr; }
/* * Class: sun_awt_shell_Win32ShellFolder * Method: getIcon * Signature: (JJZ)J */ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder_getIcon__JJZ (JNIEnv* env, jobject folder, jlong parentIShellFolder, jlong relativePIDL, jboolean getLargeIcon) { IShellFolder* pParent = (IShellFolder*)parentIShellFolder; if (pParent == NULL) { return 0; } LPITEMIDLIST pidl = (LPITEMIDLIST)relativePIDL; if (pidl == NULL) { return 0; } IExtractIcon* pIcon; if (pParent->GetUIObjectOf(NULL, 1, const_cast<LPCITEMIDLIST*>(&pidl), IID_IExtractIcon, NULL, (void**)&pIcon) != S_OK) { return 0; } CHAR szBuf[MAX_PATH]; INT index; UINT flags; if (pIcon->GetIconLocation( GIL_FORSHELL, szBuf, MAX_PATH, &index, &flags) != S_OK) { pIcon->Release(); return 0; } HICON hIcon; HICON hIconLarge; if (pIcon->Extract(szBuf, index, &hIconLarge, &hIcon, (16 << 16) + 32) != S_OK) { pIcon->Release(); return 0; } return (jlong)(getLargeIcon ? hIconLarge : hIcon); }
HRESULT GetDisplayName(LPCITEMIDLIST pidlDirectory,TCHAR *szDisplayName,UINT cchMax,DWORD uFlags) { if(pidlDirectory == NULL || szDisplayName == NULL) { return E_FAIL; } IShellFolder *pShellFolder = NULL; LPITEMIDLIST pidlRelative = NULL; STRRET str; HRESULT hr; hr = SHBindToParent(pidlDirectory, IID_PPV_ARGS(&pShellFolder), (LPCITEMIDLIST *)&pidlRelative); if(SUCCEEDED(hr)) { hr = pShellFolder->GetDisplayNameOf(pidlRelative,uFlags,&str); if(SUCCEEDED(hr)) { hr = StrRetToBuf(&str,pidlDirectory,szDisplayName,cchMax); } pShellFolder->Release(); } return hr; }
/* * Class: sun_awt_shell_Win32ShellFolder2 * Method: initSpecial * Signature: (JI)V */ JNIEXPORT void JNICALL Java_sun_awt_shell_Win32ShellFolder2_initSpecial (JNIEnv* env, jobject folder, jlong desktopIShellFolder, jint folderType) { // Get desktop IShellFolder interface IShellFolder* pDesktop = (IShellFolder*)desktopIShellFolder; if (pDesktop == NULL) { JNU_ThrowInternalError(env, "Desktop shell folder missing"); return; } // Get special folder relative PIDL LPITEMIDLIST relPIDL; HRESULT res = fn_SHGetSpecialFolderLocation(NULL, folderType, &relPIDL); if (res != S_OK) { JNU_ThrowIOException(env, "Could not get shell folder ID list"); return; } // Set field ID for relative PIDL env->CallVoidMethod(folder, MID_relativePIDL, (jlong)relPIDL); // Get special folder IShellFolder interface IShellFolder* pFolder; res = pDesktop->BindToObject(relPIDL, NULL, IID_IShellFolder, (void**)&pFolder); if (res != S_OK) { JNU_ThrowInternalError(env, "Could not bind shell folder to interface"); return; } // Set field ID for pIShellFolder env->CallVoidMethod(folder, MID_pIShellFolder, (jlong)pFolder); }
LPITEMIDLIST ShellFunctions::GetIDListForParent(LPCSTR lpszFileName) { int temp=LastCharIndex(lpszFileName,'\\'); LPCWSTR szFolder; if (temp==-1) szFolder=alloccopyAtoW(lpszFileName); else szFolder=alloccopyAtoW(lpszFileName,temp+1); LPITEMIDLIST pidl=NULL; IShellFolder *pDesktop; if (FAILED(SHGetDesktopFolder(&pDesktop))) { delete[] szFolder; return NULL; } if (FAILED(pDesktop->ParseDisplayName(NULL,NULL,(LPOLESTR)szFolder,NULL,&pidl,NULL))) { pDesktop->Release(); delete[] szFolder; return NULL; } return pidl; }
//------------------------------------------------------------------------------ // CDevicePropertyPage::GetIconFromItem [STATIC FUNC] // // Gets a handle to the icon of the shell item. phIcon needs to be cleaned // up with DestroyIcon() when done. //------------------------------------------------------------------------------ HRESULT CDevicePropertyPage::GetIconFromItem( __in IShellItem* pShellItem, __in int iImageList, __out HICON* phIcon ) { HRESULT hr = S_OK; int iIcon = 0; PITEMID_CHILD pidl = NULL; IImageList* pImageList = NULL; IParentAndItem* pParentAndItem = NULL; IShellFolder* pShellFolder = NULL; *phIcon = NULL; hr = pShellItem->QueryInterface( &pParentAndItem ); if( S_OK == hr ) { hr = pParentAndItem->GetParentAndItem( NULL, &pShellFolder, &pidl ); } if( S_OK == hr ) { hr = SHGetImageList( iImageList, __uuidof(IImageList), reinterpret_cast<void**>(&pImageList) ); } if( S_OK == hr ) { iIcon = SHMapPIDLToSystemImageListIndex( pShellFolder, pidl, NULL ); hr = pImageList->GetIcon( iIcon, 0, phIcon ); } // // Cleanup // if( NULL != pImageList ) { pImageList->Release(); } if( NULL != pidl ) { ILFree( pidl ); } if( NULL != pShellFolder ) { pShellFolder->Release(); } if( NULL != pParentAndItem ) { pParentAndItem->Release(); } return hr; }// CDevicePropertyPage::GetIconFromItem
void GetExplorerWindows(std::vector<PairHwndPath>& windows, BOOL needPaths) { IShellWindows *psw; if(SUCCEEDED(CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL, IID_IShellWindows, (void**)&psw))) { VARIANT v; V_VT(&v) = VT_I4; IDispatch* pdisp; for(V_I4(&v) = 0; psw->Item(v, &pdisp) == S_OK; V_I4(&v)++) { IWebBrowserApp *pwba; if(SUCCEEDED(pdisp->QueryInterface(IID_IWebBrowserApp, (void**)&pwba))) { PairHwndPath pair; if(SUCCEEDED(pwba->get_HWND((LONG_PTR*)&pair.hwnd))) { IServiceProvider *psp; if(needPaths && SUCCEEDED(pwba->QueryInterface(IID_IServiceProvider, (void**)&psp))) { IShellBrowser *psb; if(SUCCEEDED(psp->QueryService(SID_STopLevelBrowser, IID_IShellBrowser, (void**)&psb))) { IShellView *psv; if(SUCCEEDED(psb->QueryActiveShellView(&psv))) { IFolderView *pfv; if(SUCCEEDED(psv->QueryInterface(IID_IFolderView, (void**)&pfv))) { IPersistFolder2 *ppf2; if(SUCCEEDED(pfv->GetFolder(IID_IPersistFolder2, (void**)&ppf2))) { LPITEMIDLIST pidlFolder; if(SUCCEEDED(ppf2->GetCurFolder(&pidlFolder))) { if(!SHGetPathFromIDList(pidlFolder, pair.path)) { IShellFolder* psf; LPCITEMIDLIST pidlLast; if(SUCCEEDED(SHBindToParent(pidlFolder, IID_IShellFolder, (void**)&psf, &pidlLast))) { STRRET strret; if(SUCCEEDED(psf->GetDisplayNameOf(pidlLast, 0x8000, &strret))) { StrRetToBuf(&strret, pidlLast, pair.path, MAX_PATH); } else { pair.path[0] = 0; } psf->Release(); } } CoTaskMemFree(pidlFolder); } ppf2->Release(); } pfv->Release(); } psv->Release(); } psb->Release(); } psp->Release(); } windows.push_back(pair); } pwba->Release(); } pdisp->Release(); } psw->Release(); } }
/* TODO: These groups have changed as of Windows Vista. */ void CShellBrowser::DetermineItemTotalSizeGroup(int iItemInternal,TCHAR *szGroupHeader,int cchMax) const { IShellFolder *pShellFolder = NULL; LPITEMIDLIST pidlComplete = NULL; LPITEMIDLIST pidlDirectory = NULL; LPITEMIDLIST pidlRelative = NULL; TCHAR *SizeGroups[] = {_T("Unspecified"),_T("Small"),_T("Medium"),_T("Huge"),_T("Gigantic")}; TCHAR szItem[MAX_PATH]; STRRET str; ULARGE_INTEGER nTotalBytes; ULARGE_INTEGER nFreeBytes; BOOL bRoot; BOOL bRes = FALSE; ULARGE_INTEGER TotalSizeGroupLimits[6]; int nGroups = 5; int iSize = 0; int i; TotalSizeGroupLimits[0].QuadPart = 0; TotalSizeGroupLimits[1].QuadPart = 0; TotalSizeGroupLimits[2].QuadPart = GBYTE; TotalSizeGroupLimits[3].QuadPart = 20 * TotalSizeGroupLimits[2].QuadPart; TotalSizeGroupLimits[4].QuadPart = 100 * TotalSizeGroupLimits[2].QuadPart; GetIdlFromParsingName(m_CurDir,&pidlDirectory); pidlComplete = ILCombine(pidlDirectory,m_pExtraItemInfo[iItemInternal].pridl); SHBindToParent(pidlComplete, IID_PPV_ARGS(&pShellFolder), (LPCITEMIDLIST *) &pidlRelative); pShellFolder->GetDisplayNameOf(pidlRelative,SHGDN_FORPARSING,&str); StrRetToBuf(&str,pidlRelative,szItem,SIZEOF_ARRAY(szItem)); bRoot = PathIsRoot(szItem); if(bRoot) { bRes = GetDiskFreeSpaceEx(szItem,NULL,&nTotalBytes,&nFreeBytes); CoTaskMemFree(pidlDirectory); CoTaskMemFree(pidlComplete); pShellFolder->Release(); i = nGroups - 1; while(nTotalBytes.QuadPart < TotalSizeGroupLimits[i].QuadPart && i > 0) i--; iSize = i; } if(!bRoot || !bRes) { iSize = 0; } StringCchCopy(szGroupHeader,cchMax,SizeGroups[iSize]); }
// NOTE: Sorting added by Anatoly Ivasyuk. static int CALLBACK _SortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { IShellFolder* piSF = reinterpret_cast<IShellFolder*>(lParamSort); PSHELLITEMINFO pItem1 = reinterpret_cast<PSHELLITEMINFO>(lParam1); PSHELLITEMINFO pItem2 = reinterpret_cast<PSHELLITEMINFO>(lParam2); HRESULT Hr = piSF->CompareIDs(0, pItem1->pidlNode, pItem2->pidlNode); if( SUCCEEDED(Hr) ) return (SHORT) (Hr & SHCIDS_COLUMNMASK); return 0; }
/** * 폴더 가져오기 */ BOOL GetFolder(CString* strSelectedFolder, const char* lpszTitle, const HWND hwndOwner, const char* strRootFolder, const char* strStartFolder) { char pszDisplayName[ MAX_PATH ]; LPITEMIDLIST lpID; BROWSEINFOA bi; bi.hwndOwner = hwndOwner; if (strRootFolder == NULL) { bi.pidlRoot = NULL; } else { LPITEMIDLIST pIdl = NULL; IShellFolder* pDesktopFolder; char szPath[ MAX_PATH ]; OLECHAR olePath[ MAX_PATH ]; ULONG chEaten; ULONG dwAttributes; strcpy(szPath, (LPCTSTR)strRootFolder); if (SUCCEEDED (SHGetDesktopFolder (&pDesktopFolder))) { MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, szPath, -1, olePath, MAX_PATH); pDesktopFolder->ParseDisplayName (NULL, NULL, olePath, &chEaten, &pIdl, &dwAttributes); pDesktopFolder->Release (); } bi.pidlRoot = pIdl; } bi.pszDisplayName = pszDisplayName; bi.lpszTitle = lpszTitle; bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; bi.lpfn = BrowseCallbackProc; if (strStartFolder == NULL) { bi.lParam = FALSE; } else { strTmpPath.Format ("%s", strStartFolder); bi.lParam = TRUE; } bi.iImage = NULL; lpID = SHBrowseForFolderA(&bi); if (lpID != NULL) { BOOL b = SHGetPathFromIDList (lpID, pszDisplayName); if (b == TRUE) { strSelectedFolder->Format ("%s",pszDisplayName); return TRUE; } } else { strSelectedFolder->Empty (); } return FALSE; }
/* * Class: sun_awt_shell_Win32ShellFolder2 * Method: compareIDs * Signature: (JJJ)I */ JNIEXPORT jint JNICALL Java_sun_awt_shell_Win32ShellFolder2_compareIDs (JNIEnv* env, jclass cls, jlong jpParentIShellFolder, jlong pIDL1, jlong pIDL2) { IShellFolder* pParentIShellFolder = (IShellFolder*)jpParentIShellFolder; if (pParentIShellFolder == NULL) { return 0; } return pParentIShellFolder->CompareIDs(0, (LPCITEMIDLIST) pIDL1, (LPCITEMIDLIST) pIDL2); }
void FillItemVector() { // 1. Desktop #ifdef SUPPORT_CURFOLDER_AS_ITEM ShellFolderWithPidl aDesktop; SHGetDesktopFolder(&aDesktop.SF); SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &aDesktop.Pidl); myItems.push_back( aDesktop ); #else myItems.push_back( new ShellFolder(CSIDL_DESKTOP) ); #endif // 2. Others if (myEnumerationPidl->mkid.cb == 0) return; LPCITEMIDLIST aTempPidl = myEnumerationPidl; IShellFolder * aTempSF = 0; SHGetDesktopFolder(&aTempSF); while(aTempPidl != 0) { // the PIDL needs not be destroyed here since ShellFolder will destroy it LPITEMIDLIST aLocalSinglePidl = UtilPidlFunc::Copy<MemoryWriter_Crt>(aTempPidl, aTempPidl->mkid.cb); #ifdef SUPPORT_CURFOLDER_AS_ITEM myItems.push_back( ShellFolderWithPidl(aTempSF, aLocalSinglePidl) ); #else myItems.push_back( new ShellFolder(aLocalSinglePidl, aTempSF) ); #endif // Advance the Shell Folder to the next PIDL IShellFolder * aSF = 0; HRESULT aRes = aTempSF->BindToObject(aLocalSinglePidl, NULL, IID_IShellFolder, (void **) &aSF); if ( FAILED(aRes) || aSF == 0) break; aTempSF->Release(); aTempSF = aSF; // Advance the PIDL aTempPidl = UtilPidlFunc::GetNextItemID(aTempPidl); } aTempSF->Release(); }
static HRESULT GetDesktopShellView( __in REFIID riid, __out void **ppv ) { HRESULT hr = S_OK; IShellWindows* psw = NULL; HWND hwnd = NULL; IDispatch* pdisp = NULL; VARIANT vEmpty = {}; // VT_EMPTY IShellBrowser* psb = NULL; IShellFolder* psf = NULL; IShellView* psv = NULL; // use the shell view for the desktop using the shell windows automation to find the // desktop web browser and then grabs its view // returns IShellView, IFolderView and related interfaces hr = ::CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&psw)); ExitOnFailure(hr, "Failed to get shell view."); hr = psw->FindWindowSW(&vEmpty, &vEmpty, SWC_DESKTOP, (long*)&hwnd, SWFO_NEEDDISPATCH, &pdisp); if (S_OK == hr) { hr = IUnknown_QueryService(pdisp, SID_STopLevelBrowser, IID_PPV_ARGS(&psb)); ExitOnFailure(hr, "Failed to get desktop window."); hr = psb->QueryActiveShellView(&psv); ExitOnFailure(hr, "Failed to get active shell view."); hr = psv->QueryInterface(riid, ppv); ExitOnFailure(hr, "Failed to query for the desktop shell view."); } else if (S_FALSE == hr) { //Windows XP hr = SHGetDesktopFolder(&psf); ExitOnFailure(hr, "Failed to get desktop folder."); hr = psf->CreateViewObject(NULL, IID_IShellView, ppv); ExitOnFailure(hr, "Failed to query for the desktop shell view."); } else { ExitOnFailure(hr, "Failed to get desktop window."); } LExit: ReleaseObject(psv); ReleaseObject(psb); ReleaseObject(psf); ReleaseObject(pdisp); ReleaseObject(psw); return hr; }
LPITEMIDLIST ShellFunctions::GetIDList(LPCWSTR lpszFileName) { LPITEMIDLIST pidl=NULL; IShellFolder *pDesktop; if (FAILED(SHGetDesktopFolder(&pDesktop))) return NULL; HRESULT hRes=pDesktop->ParseDisplayName(NULL,NULL,(LPOLESTR)lpszFileName,NULL,&pidl,NULL); pDesktop->Release(); return FAILED(hRes)?NULL:pidl; }
/** * 简单的枚举文件夹内容,返回内容数量 */ int SimpleEnumFolder(LPCTSTR lpszPath // 文件夹路径 , CShellManager* pShellManager // Shell管理器 , function<void(LPITEMIDLIST)> filter) // 过滤器函数 { ENSURE(lpszPath != nullptr); ASSERT_VALID(pShellManager); AFX_SHELLITEMINFO info; HRESULT hr = pShellManager->ItemFromPath(lpszPath, info.pidlRel); if (FAILED(hr)) { return 0; } int nFolderCount = 0; LPSHELLFOLDER pDesktopFolder; hr = SHGetDesktopFolder(&pDesktopFolder); if (SUCCEEDED(hr)) { IShellFolder* psfCurFolder = nullptr; hr = pDesktopFolder->BindToObject(info.pidlRel, nullptr, IID_IShellFolder, (LPVOID*)&psfCurFolder); LPENUMIDLIST pEnum = nullptr; HRESULT hRes = psfCurFolder->EnumObjects(nullptr, (SHCONTF)(SHCONTF_FOLDERS), &pEnum); if (SUCCEEDED(hRes) && pEnum != nullptr) { DWORD dwFetched = 1; LPITEMIDLIST pidlTemp; while (pEnum->Next(1, &pidlTemp, &dwFetched) == S_OK && dwFetched) { if (!filter._Empty()) { LPITEMIDLIST itemID = pShellManager->ConcatenateItem(info.pidlRel, pidlTemp); filter(itemID); pShellManager->FreeItem(itemID); } pShellManager->FreeItem(pidlTemp); nFolderCount++; dwFetched = 0; } pEnum->Release(); } psfCurFolder->Release(); pDesktopFolder->Release(); } pShellManager->FreeItem(info.pidlRel); return nFolderCount; }
/* * Class: sun_awt_shell_Win32ShellFolder * Method: initFile * Signature: (JLjava/lang/String;Z)J */ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder_initFile (JNIEnv* env, jobject folder, jlong desktopIShellFolder, jstring absolutePath, jboolean initAttributes) { // Get desktop IShellFolder interface IShellFolder* pDesktop = (IShellFolder*)desktopIShellFolder; if (pDesktop == NULL) { JNU_ThrowInternalError(env, "Desktop shell folder missing"); return 0; } // Get PIDL for file from desktop LPITEMIDLIST pIDL; int nLength = env->GetStringLength(absolutePath); jchar* wszPath = new jchar[nLength + 1]; const jchar* strPath = env->GetStringChars(absolutePath, NULL); wcsncpy(wszPath, strPath, nLength); wszPath[nLength] = 0; HRESULT res = pDesktop->ParseDisplayName(NULL, NULL, const_cast<jchar*>(wszPath), NULL, &pIDL, NULL); if (res != S_OK) { JNU_ThrowIOException(env, "Could not parse file path"); delete[] wszPath; env->ReleaseStringChars(absolutePath, strPath); return 0; } delete[] wszPath; env->ReleaseStringChars(absolutePath, strPath); // Get display name, folder type, and possibly attributes SHFILEINFO fileInfo; UINT flags; if (initAttributes) { flags = SHGFI_ATTRIBUTES | SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_PIDL; } else { flags = SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_PIDL; } if (fn_SHGetFileInfo((char *)pIDL, 0L, &fileInfo, sizeof(fileInfo), flags) != 0) { if (initAttributes) { env->SetLongField(folder, FID_attributes, (jlong)fileInfo.dwAttributes); } env->SetObjectField(folder, FID_displayName, JNU_NewStringPlatform(env, fileInfo.szDisplayName)); env->SetObjectField(folder, FID_folderType, JNU_NewStringPlatform(env, fileInfo.szTypeName)); } return (jlong)pIDL; }
int CALLBACK PidlListSort(void* item1, void* item2, LPARAM lParam) { IShellFolder * psf = (IShellFolder*) lParam; PCUIDLIST_RELATIVE pidl1 = (PCUIDLIST_RELATIVE) item1; PCUIDLIST_RELATIVE pidl2 = (PCUIDLIST_RELATIVE) item2; HRESULT hr = psf->CompareIDs(0, pidl1, pidl2); if (FAILED(hr)) { // No way to cancel, so sort to equal. return 0; } return (int)(short)LOWORD(hr); }
/* TODO: Need to sort based on percentage free. */ void CShellBrowser::DetermineItemFreeSpaceGroup(int iItemInternal,TCHAR *szGroupHeader,int cchMax) const { std::list<TypeGroup_t>::iterator itr; LPITEMIDLIST pidlComplete = NULL; LPITEMIDLIST pidlDirectory = NULL; TCHAR szFreeSpace[MAX_PATH]; IShellFolder *pShellFolder = NULL; LPITEMIDLIST pidlRelative = NULL; STRRET str; TCHAR szItem[MAX_PATH]; ULARGE_INTEGER nTotalBytes; ULARGE_INTEGER nFreeBytes; BOOL bRoot; BOOL bRes = FALSE; GetIdlFromParsingName(m_CurDir,&pidlDirectory); pidlComplete = ILCombine(pidlDirectory,m_pExtraItemInfo[iItemInternal].pridl); SHBindToParent(pidlComplete, IID_PPV_ARGS(&pShellFolder), (LPCITEMIDLIST *)&pidlRelative); pShellFolder->GetDisplayNameOf(pidlRelative,SHGDN_FORPARSING,&str); StrRetToBuf(&str,pidlRelative,szItem,SIZEOF_ARRAY(szItem)); CoTaskMemFree(pidlDirectory); CoTaskMemFree(pidlComplete); pShellFolder->Release(); bRoot = PathIsRoot(szItem); if(bRoot) { bRes = GetDiskFreeSpaceEx(szItem,NULL,&nTotalBytes,&nFreeBytes); LARGE_INTEGER lDiv1; LARGE_INTEGER lDiv2; lDiv1.QuadPart = 100; lDiv2.QuadPart = 10; /* Divide by 10 to remove the one's digit, then multiply by 10 so that only the ten's digit rmains. */ StringCchPrintf(szFreeSpace,SIZEOF_ARRAY(szFreeSpace), _T("%I64d%% free"),(((nFreeBytes.QuadPart * lDiv1.QuadPart) / nTotalBytes.QuadPart) / lDiv2.QuadPart) * lDiv2.QuadPart); } if(!bRoot || !bRes) { StringCchCopy(szFreeSpace,SIZEOF_ARRAY(szFreeSpace),_T("Unspecified")); } StringCchCopy(szGroupHeader,cchMax,szFreeSpace); }
HRESULT CDropHandler::CopyShellIDListData(IDataObject *pDataObject, list<PastedFile_t> *pPastedFileList) { STGMEDIUM stg; HRESULT hr; hr = pDataObject->GetData(&m_ftcShellIDList,&stg); if(hr == S_OK) { CIDA *pcida = (CIDA *)GlobalLock(stg.hGlobal); if(pcida != NULL) { IShellFolder *pShellFolder = NULL; HRESULT hr; LPCITEMIDLIST pidlDirectory = HIDA_GetPIDLFolder(pcida); hr = BindToShellFolder(pidlDirectory,&pShellFolder); if(SUCCEEDED(hr)) { LPCITEMIDLIST pidlItem = NULL; IStorage *pStorage = NULL; for(unsigned int i = 0;i < pcida->cidl;i++) { pidlItem = HIDA_GetPIDLItem(pcida,i); hr = pShellFolder->BindToStorage(pidlItem,NULL,IID_IStorage,(LPVOID *)&pStorage); if(SUCCEEDED(hr)) { /* TODO: Copy the files. */ pStorage->Release(); } } pShellFolder->Release(); } GlobalUnlock(stg.hGlobal); } ReleaseStgMedium(&stg); } return hr; }
// Retrieves the UIObject interface for the specified full PIDL STDAPI SHGetUIObjectFromFullPIDL(LPITEMIDLIST pidl, HWND hwnd, REFIID riid, void **ppv) { LPCITEMIDLIST pidlChild; IShellFolder* psf; *ppv = NULL; HRESULT hr = SHBindToParent(pidl, IID_IShellFolder, (void**)(&psf), &pidlChild); if (SUCCEEDED(hr)) { hr = psf->GetUIObjectOf(hwnd, 1, &pidlChild, riid, NULL, ppv); psf->Release(); } return hr; }
/* * Class: sun_awt_shell_Win32ShellFolder2 * Method: getAttributes0 * Signature: (JJI)J */ JNIEXPORT jint JNICALL Java_sun_awt_shell_Win32ShellFolder2_getAttributes0 (JNIEnv* env, jclass cls, jlong jpParentIShellFolder, jlong jpIDL, jint attrsMask) { IShellFolder* pParentIShellFolder = (IShellFolder*)jpParentIShellFolder; if (pParentIShellFolder == NULL) { return 0; } LPCITEMIDLIST pIDL = (LPCITEMIDLIST)jpIDL; if (pIDL == NULL) { return 0; } ULONG attrs = attrsMask; HRESULT res = pParentIShellFolder->GetAttributesOf(1, &pIDL, &attrs); return attrs; }