本文整理汇总了C++中IShellFolder::ParseDisplayName方法的典型用法代码示例。如果您正苦于以下问题:C++ IShellFolder::ParseDisplayName方法的具体用法?C++ IShellFolder::ParseDisplayName怎么用?C++ IShellFolder::ParseDisplayName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IShellFolder
的用法示例。
在下文中一共展示了IShellFolder::ParseDisplayName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetObjects
void CShellContextMenu::SetObjects(const QStringList &strList)
{
// free all allocated datas
if (m_psfFolder && bDelete)
m_psfFolder->Release ();
m_psfFolder = NULL;
FreePIDLArray (m_pidlArray);
m_pidlArray = NULL;
// get IShellFolder interface of Desktop (root of shell namespace)
IShellFolder * psfDesktop = NULL;
SHGetDesktopFolder (&psfDesktop); // needed to obtain full qualified pidl
// ParseDisplayName creates a PIDL from a file system path relative to the IShellFolder interface
// but since we use the Desktop as our interface and the Desktop is the namespace root
// that means that it's a fully qualified PIDL, which is what we need
LPITEMIDLIST pidl = NULL;
psfDesktop->ParseDisplayName (NULL, 0, (LPOLESTR)strList[0].utf16(), NULL, &pidl, NULL);
// now we need the parent IShellFolder interface of pidl, and the relative PIDL to that interface
LPITEMIDLIST pidlItem = NULL; // relative pidl
SHBindToParentEx (pidl, IID_IShellFolder, (void **) &m_psfFolder, NULL);
free (pidlItem);
// get interface to IMalloc (need to free the PIDLs allocated by the shell functions)
LPMALLOC lpMalloc = NULL;
SHGetMalloc (&lpMalloc);
lpMalloc->Free (pidl);
// now we have the IShellFolder interface to the parent folder specified in the first element in strArray
// since we assume that all objects are in the same folder (as it's stated in the MSDN)
// we now have the IShellFolder interface to every objects parent folder
IShellFolder * psfFolder = NULL;
nItems = strList.size ();
for (int i = 0; i < nItems; i++)
{
pidl=0;
psfDesktop->ParseDisplayName (NULL, 0, (LPOLESTR)strList[i].utf16(), NULL, &pidl, NULL);
if (pidl)
{
m_pidlArray = (LPITEMIDLIST *) realloc (m_pidlArray, (i + 1) * sizeof (LPITEMIDLIST));
// get relative pidl via SHBindToParent
SHBindToParentEx (pidl, IID_IShellFolder, (void **) &psfFolder, (LPCITEMIDLIST *) &pidlItem);
m_pidlArray[i] = CopyPIDL (pidlItem); // copy relative pidl to pidlArray
free (pidlItem);
lpMalloc->Free (pidl); // free pidl allocated by ParseDisplayName
psfFolder->Release ();
}
}
lpMalloc->Release ();
psfDesktop->Release ();
bDelete = TRUE; // indicates that m_psfFolder should be deleted by CShellContextMenu
}
示例2: GetIDListForParent
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;
}
示例3: GetItemIDListFromPath
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;
}
示例4: GetIdlFromParsingName
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;
}
示例5: wcsncpy
/*
* 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;
}
示例6: GetFolder
/**
* 폴더 가져오기
*/
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;
}
示例7: GetIDList
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;
}
示例8: wcsncpy
/*
* 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;
}
示例9: SHGetContextMenu
HRESULT CContextMenuHelper::SHGetContextMenu(std::vector<LPCTSTR> files) {
HRESULT hr;
IMalloc *pm = NULL;
IShellFolder *pDesktop = NULL;
IShellFolder *psf = NULL;
LPITEMIDLIST pidl = NULL;
WCHAR fwname[MAX_PATH + 1];
if (SUCCEEDED(hr = SHGetMalloc(&pm))) {
if (SUCCEEDED(hr = SHGetDesktopFolder(&pDesktop))) {
std::vector<LPITEMIDLIST> pidls;
IShellFolder* psfFolder = NULL;
for (UINT i = 0; SUCCEEDED(hr) && i < files.size(); i++) {
LPCTSTR lpszFilePath = files[i];
ULONG cch;
ULONG attrs;
// Convert to Unicode
memset(fwname, L'\0', (MAX_PATH + 1) * sizeof(WCHAR));
MultiByteToWideChar(CP_THREAD_ACP, 0, lpszFilePath, -1, fwname, MAX_PATH);
if (SUCCEEDED(hr = pDesktop->ParseDisplayName(m_hWnd, NULL, fwname, &cch, &pidl, &attrs))) {
LPITEMIDLIST pidlItem = NULL;
if (SUCCEEDED(hr = SHBindToParentEx((LPCITEMIDLIST)pidl, IID_IShellFolder, (void **)&psf, (LPCITEMIDLIST *) &pidlItem, pDesktop, pm))) {
pidls.push_back(CopyPIDL(pidlItem, pm));
pm->Free(pidlItem);
if (psfFolder == NULL) {
// Remember first folder and we wiil show menu for this one
// All other folder will be ignored
psfFolder = psf;
} else {
psf->Release();
}
}
pm->Free(pidl);
}
}
if (SUCCEEDED(hr) && psfFolder != NULL) {
hr = psfFolder->GetUIObjectOf(m_hWnd, pidls.size(), const_cast<LPCITEMIDLIST*>(pidls.begin()), IID_IContextMenu, NULL, (void**)&m_lpcm);
psfFolder->Release();
}
FreeItemIDList(pidls, pm);
pDesktop->Release();
}
pm->Release();
}
return hr;
}
示例10: lana_ShellGetNameFromGuidW
// Use the IShellFolder API to get the connection name for the given Guid.
static HRESULT lana_ShellGetNameFromGuidW(WCHAR *wGuid, WCHAR *wName, int NameSize)
{
// This is the GUID for the network connections folder. It is constant.
// {7007ACC7-3202-11D1-AAD2-00805FC1270E}
const GUID CLSID_NetworkConnections = {
0x7007ACC7, 0x3202, 0x11D1, {
0xAA, 0xD2, 0x00, 0x80, 0x5F, 0xC1, 0x27, 0x0E
}
};
LPITEMIDLIST pidl;
IShellFolder *pShellFolder;
IMalloc *pShellMalloc;
// Build the display name in the form "::{GUID}".
if (wcslen(wGuid) >= MAX_PATH)
return E_INVALIDARG;
WCHAR szAdapterGuid[MAX_PATH + 2];
swprintf(szAdapterGuid, L"::%ls", wGuid);
// Initialize COM.
CoInitialize(NULL);
// Get the shell allocator.
HRESULT hr = SHGetMalloc(&pShellMalloc);
if (SUCCEEDED(hr))
{
// Create an instance of the network connections folder.
hr = CoCreateInstance(CLSID_NetworkConnections, NULL,
CLSCTX_INPROC_SERVER, IID_IShellFolder,
reinterpret_cast<LPVOID *>(&pShellFolder));
}
if (SUCCEEDED(hr))
{
hr = pShellFolder->ParseDisplayName(NULL, NULL, szAdapterGuid, NULL,
&pidl, NULL);
}
if (SUCCEEDED(hr)) {
// Get the display name; this returns the friendly name.
STRRET sName;
hr = pShellFolder->GetDisplayNameOf(pidl, SHGDN_NORMAL, &sName);
if (SUCCEEDED(hr))
wcsncpy(wName, sName.pOleStr, NameSize);
pShellMalloc->Free(pidl);
}
CoUninitialize();
return hr;
}
示例11: CoCreateInstance
//
// NB: This function leaks memory/references.
//
EXTERN_C void
RenameAdapter(const GUID *AdapterGuid, const WCHAR *NewName)
{
HRESULT hr;
IShellFolder *pShellFolder;
hr = CoCreateInstance(CLSID_NetworkConnections, NULL,
CLSCTX_INPROC_SERVER,
IID_IShellFolder,
reinterpret_cast<LPVOID *>(&pShellFolder));
if (FAILED(hr)) {
fprintf(stderr, "mcl: RenameAdapter: CoCreateInstance: %x\n", hr);
return;
}
LPOLESTR szClsId;
hr = StringFromCLSID(*AdapterGuid, &szClsId);
if (FAILED(hr)) {
fprintf(stderr, "mcl: RenameAdapter: StringFromCLSID: %x\n", hr);
return;
}
WCHAR szAdapterGuid[MAX_PATH];
swprintf(szAdapterGuid, L"::%s", szClsId);
LPITEMIDLIST pidl;
hr = pShellFolder->ParseDisplayName(NULL, NULL,
szAdapterGuid, NULL,
&pidl, NULL);
if (FAILED(hr)) {
fprintf(stderr, "mcl: RenameAdapter: ParseDisplayName: %x\n", hr);
return;
}
hr = pShellFolder->SetNameOf(NULL, pidl, NewName, SHGDN_NORMAL, &pidl);
if (FAILED(hr)) {
fprintf(stderr, "mcl: RenameAdapter: SetNameOf: %x\n", hr);
return;
}
}
示例12: SetRootFolder
BOOL CFolderDialog::SetRootFolder(IN LPCTSTR pszPath)
{
ASSERT_VALID(this);
if (!pszPath)
{
SAFE_COTASKMEMFREE(m_bi.pidlRoot);
return TRUE;
}
ASSERT(AfxIsValidString(pszPath, MAX_PATH));
HRESULT hResult = S_FALSE;
IShellFolder* pDeskFolder = NULL;
hResult = ::SHGetDesktopFolder(&pDeskFolder);
if (hResult == S_OK)
{
LPITEMIDLIST pidlRoot = NULL;
LPTSTR pszRoot = const_cast< LPTSTR >(pszPath);
// Convert the path to an ITEMIDLIST:
USES_CONVERSION;
hResult = pDeskFolder->ParseDisplayName(
NULL, NULL, T2W(pszRoot), NULL, &pidlRoot, NULL
);
if (hResult == S_OK)
{
SAFE_COTASKMEMFREE(m_bi.pidlRoot);
m_bi.pidlRoot = pidlRoot;
}
SAFE_RELEASE(pDeskFolder);
}
return (hResult == S_OK);
}
示例13: SetRootFolder
BOOL CFolderDialog::SetRootFolder( IN LPCTSTR pszPath )
{
ASSERT_VALID( this );
if( pszPath == NULL )
{
_coTaskMemFree( m_bi.pidlRoot );
return ( TRUE );
}
ASSERT( AfxIsValidString( pszPath, MAX_PATH ) );
HRESULT hResult = S_FALSE;
IShellFolder* pDeskFolder = NULL;
if ( ( hResult = ::SHGetDesktopFolder( &pDeskFolder ) ) == S_OK )
{
LPITEMIDLIST pidlRoot = NULL;
LPTSTR pszRoot = const_cast< LPTSTR >( pszPath );
// Convert the path to an ITEMIDLIST:
USES_CONVERSION;
hResult = pDeskFolder->ParseDisplayName(
NULL, NULL, T2W( pszRoot ), NULL, &pidlRoot, NULL
);
if ( hResult == S_OK )
{
_coTaskMemFree( m_bi.pidlRoot );
m_bi.pidlRoot = pidlRoot;
}
_releaseInterface( pDeskFolder );
}
return ( hResult == S_OK );
}
示例14: GetThumbNail
BOOL GetThumbNail(HDC hDC, LPCTSTR lpszFilePath,LPCTSTR lpszSavepath)
{
bool bFileExit = PathFileExists(lpszSavepath);
if(bFileExit)
return TRUE;
IShellFolder * pShellFolder = NULL;
if( SHGetDesktopFolder( &pShellFolder) == S_OK )
{
LPITEMIDLIST pidl = NULL;
HRESULT hRes = pShellFolder->ParseDisplayName( NULL, NULL, (LPTSTR)(LPCTSTR)lpszFilePath, NULL, &pidl, NULL);
if( hRes == S_OK )
{
LPCITEMIDLIST pidlLast = NULL;
IShellFolder * pParentFolder = NULL;
HRESULT hRes = SHBindToParent( pidl, IID_IShellFolder, (void**)&pParentFolder, &pidlLast );
if( hRes == S_OK )
{
HBITMAP hBmpImage = ExtractThumb(pParentFolder, pidlLast );
if( hBmpImage )
{
SaveImage(hDC,hBmpImage,lpszSavepath);
//HBITMAP hbmpOld = hBmpImage;
//if( hbmpOld )
// DeleteObject(hbmpOld);
}
else
return false;
pParentFolder->Release();
}
}
pShellFolder->Release();
return true;
}
return false;
}
示例15: AddContextMenu
HRESULT AddContextMenu(WCHAR* file)
{
HRESULT hr = E_UNEXPECTED;
LPVOID lpVoid;
HMENU fileMenu = CreatePopupMenu();
IShellFolder* deskFolder = NULL;
IShellFolder* appObject = NULL;
LPITEMIDLIST pidlLocal = NULL;
LPITEMIDLIST pidlRelative = NULL;
IContextMenu* contextMenu = NULL;
CONTEXTINFO contextInfo;
wcscpy(contextInfo.value, file);
hr = SHGetDesktopFolder(&deskFolder);
if (FAILED(hr))
{
return hr;
}
hr = deskFolder->ParseDisplayName(NULL, NULL, file, NULL, &pidlLocal, NULL);
if (FAILED(hr))
{
deskFolder->Release();
return hr;
}
pidlRelative = ILClone(ILFindLastID(pidlLocal));
ILRemoveLastID(pidlLocal);
hr = deskFolder->BindToObject(pidlLocal, NULL, IID_IShellFolder, &lpVoid);
if (FAILED(hr))
{
deskFolder->Release();
ILFree(pidlLocal);
return hr;
}
appObject = reinterpret_cast <IShellFolder*> (lpVoid);
deskFolder->Release();
ILFree(pidlLocal);
hr = appObject->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*)&pidlRelative,
IID_IContextMenu, NULL, &lpVoid);
if (FAILED(hr))
{
appObject->Release();
ILFree(pidlRelative);
return hr;
}
contextMenu = reinterpret_cast <IContextMenu*> (lpVoid);
ILFree(pidlRelative);
appObject->Release();
contextMenu->QueryInterface(IID_IContextMenu2, &lpVoid);
if (FAILED(hr))
{
contextMenu->Release();
return hr;
}
contextInfo.ic2 = reinterpret_cast <IContextMenu2*> (lpVoid);
contextMenu->Release();
hr = contextInfo.ic2->QueryContextMenu(fileMenu, 0, SYSMENUMIN, SYSMENUMAX, CMF_NORMAL);
if (FAILED(hr))
{
contextInfo.ic2->Release();
return hr;
}
if (!ELIsDirectory(file))
{
AppendMenu(fileMenu, MF_SEPARATOR, 0x8000, NULL);
AppendMenu(fileMenu, MF_STRING, 0x8001, TEXT("Open Folder"));
}
contextMap.insert(std::pair<HMENU, CONTEXTINFO>(fileMenu, contextInfo));
return hr;
}