Пример #1
0
// parent IShellFolder, simple PIDL -> IShellFolder
xpr_bool_t Pidl::getShellFolder(LPSHELLFOLDER aParentShellFolder, LPCITEMIDLIST aPidl, LPSHELLFOLDER &aShellFolder)
{
    XPR_ASSERT(aParentShellFolder != XPR_NULL);
    XPR_ASSERT(aPidl != XPR_NULL);

    HRESULT sComResult;

    sComResult = aParentShellFolder->BindToObject(
        (LPCITEMIDLIST)aPidl,
        0,
        IID_IShellFolder,
        reinterpret_cast<LPVOID *>(&aShellFolder));

    if (FAILED(sComResult) || XPR_IS_NULL(aShellFolder))
    {
        sComResult = ::SHGetDesktopFolder(&aShellFolder); // desktop PIDL is null.

        if (FAILED(sComResult))
        {
            return XPR_FALSE;
        }
    }

    return XPR_TRUE;
}
Пример #2
0
BOOL CRecBinViewer::GetFolder2 ()
{
	BOOL			bReturn			= FALSE;
	STRRET			strRet;
	LPSHELLFOLDER	pDesktop		= NULL;
	LPITEMIDLIST	pidlRecycleBin	= NULL;
	CString			dspName;

	
	if (NULL != m_pFolder2)
	{
		m_pFolder2->Release ();
		m_pFolder2 = NULL;
	}
	
	if ((SUCCEEDED (SHGetDesktopFolder(&pDesktop))) &&
		(SUCCEEDED (SHGetSpecialFolderLocation (m_hWnd, CSIDL_BITBUCKET, &pidlRecycleBin))))
	{
		if (SUCCEEDED (pDesktop->BindToObject(pidlRecycleBin, NULL, IID_IShellFolder2, (LPVOID *)&m_pFolder2)))
		{
			if (S_OK == pDesktop->GetDisplayNameOf (pidlRecycleBin, SHGDN_NORMAL, &strRet))			
				GetName (strRet, dspName);			
			bReturn = TRUE;
		}
	}
		
	CoTaskMemFree (pidlRecycleBin);
	
	if (NULL != pDesktop) pDesktop->Release();
	
	return bReturn;
}
Пример #3
0
/**
 * 简单的枚举文件夹内容,返回内容数量
 */
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;
}
bool CXTPShellListCtrlEx::BrowseToFolder(LPCTSTR lpszPath)
{
	XTP_TVITEMDATA lpTVID;

	LPITEMIDLIST  pidl;
	LPSHELLFOLDER pDesktopFolder;
	OLECHAR       szOleChar[MAX_PATH];
	ULONG         chEaten;
	ULONG         dwAttributes;
	HRESULT       hr;

	// Get a pointer to the Desktop's IShellFolder interface.
	if (SUCCEEDED(::SHGetDesktopFolder(&pDesktopFolder)))
	{
		// IShellFolder::ParseDisplayName requires the file name be in
		// Unicode.

#if !defined(_UNICODE)
		::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszPath, -1,
			szOleChar, MAX_PATH);
#else
		STRCPY_S(szOleChar, MAX_PATH, lpszPath);
#endif

		// Convert the path to an ITEMIDLIST.
		hr = pDesktopFolder->ParseDisplayName(NULL, NULL, szOleChar,
			&chEaten, &pidl, &dwAttributes);

		if (SUCCEEDED(hr))
		{
			IShellFolder *psfMyFolder;

			lpTVID.lpi = lpTVID.lpifq = pidl;

			pDesktopFolder->BindToObject(lpTVID.lpifq, NULL,
				IID_IShellFolder, (LPVOID*)&psfMyFolder);

			lpTVID.lpsfParent = psfMyFolder;
			PopulateListView(&lpTVID, lpTVID.lpsfParent);

			m_strItemPath = lpszPath;
			pDesktopFolder->Release();

			return true;
		}

		pDesktopFolder->Release();
	}

	return false;
}
LPSHELLFOLDER COXShellNamespaceNavigator::
GetShellFolder(const LPSHELLFOLDER lpParentFolder, 
			   const LPITEMIDLIST lpRelativeIDL) const
{
	ASSERT(lpParentFolder!=NULL);

	LPSHELLFOLDER lpsf;
	// We use IShellFolder::BindToObject method to get IShellFolder interface
	// of expanded item. Don't forget that this interface take relative PIDL as
	// an argument
	HRESULT hResult=lpParentFolder->BindToObject(lpRelativeIDL,0,
		IID_IShellFolder,(LPVOID*)&lpsf);

	if(SUCCEEDED(hResult))
		return lpsf;
	else
		return NULL;
}
Пример #6
0
BOOL showContextMenu (HWND hDlg, TCHAR* FName, WNDPROC menuProc)
{
	TCHAR* FileName = PathFindFileName (FName);
	TCHAR FilePath [MAX_PATH];
	lstrcpy (FilePath, FName);
	*PathFindFileName (FilePath) = L'\0';
	
	LPSHELLFOLDER DesktopFolder;
	if (NOERROR != SHGetDesktopFolder (&DesktopFolder))
	{
		return FALSE;
	}
	
	LPITEMIDLIST ParentPidl;
	ULONG Eaten;
	if (S_OK != DesktopFolder->ParseDisplayName (hDlg, 0, FilePath, &Eaten, &ParentPidl, 0))
	{
		return FALSE;
	}
	
	LPSHELLFOLDER ParentFolder;
	if (S_OK != DesktopFolder->BindToObject (ParentPidl, 0, IID_IShellFolder, (void**)&ParentFolder))
	{
		return FALSE;
	}
	
	LPITEMIDLIST Pidl;
	if (S_OK != ParentFolder->ParseDisplayName (hDlg, 0, FileName, &Eaten, &Pidl, 0))
	{
		return FALSE;
	}	

	LPCONTEXTMENU CM;
	if (S_OK != ParentFolder->GetUIObjectOf (hDlg, 1, (LPCITEMIDLIST*)&Pidl, IID_IContextMenu, 0, (void**)&CM))
	{
		return FALSE;
	}
	
	HMENU hMenu = CreatePopupMenu ();
	if (hMenu == NULL) 
	{
		return FALSE;
	}
	
	CM->QueryContextMenu (hMenu, 0, 1, 0x7FFF, CMF_EXTENDEDVERBS | CMF_EXPLORE);
	
	WNDPROC defWndProc = (WNDPROC) SetWindowLong (hDlg, GWL_WNDPROC, (LONG)menuProc);
	SetProp (hDlg, L"defWndProc", (HANDLE) defWndProc);
	
	POINT pt;
	GetCursorPos (&pt);
	int Cmd = TrackPopupMenu (hMenu,
		TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD,
		pt.x, pt.y, 0, hDlg, 0);


	SetWindowLong (hDlg, GWL_WNDPROC, (LONG) RemoveProp (hDlg, L"defWndProc"));
		
	if (Cmd)
	{
		// Set up a CMINVOKECOMMANDINFO structure.
		CMINVOKECOMMANDINFO CI;
		ZeroMemory (&CI, sizeof(CMINVOKECOMMANDINFO));
		CI.cbSize = sizeof (CMINVOKECOMMANDINFO);
		CI.hwnd = hDlg;
		CI.lpVerb = (LPCSTR) MAKEINTRESOURCE(Cmd - 1);
		CI.lpParameters = "";
		CI.lpDirectory = "";
		CI.nShow = SW_SHOWNORMAL;
		CM->InvokeCommand (&CI);
	}
	
	return DestroyMenu (hMenu);
}
Пример #7
0
/**
 * Begin a saved search.
 */
JNIEXPORT jlong JNICALL WindowsSavedSearch_METHOD(beginSearch)
    ( JNIEnv *env, jclass, jstring jPath )
{
    jstring_to_c const cPath( env, jPath );

    SavedSearch*    cSavedSearch = NULL;
    bool            error = false;
    LPITEMIDLIST    pidl = NULL;
    LPSHELLFOLDER   pDesktop = NULL;
    HRESULT         result;

    if ( FAILED( ::CoInitialize( NULL ) ) )
        goto error;

    cSavedSearch = new SavedSearch;

    if ( FAILED( ::SHGetMalloc( &cSavedSearch->m_pMalloc ) ) )
        goto error;

    //
    // We have to start at the filesystem root (the "Desktop" in Windows).
    //
    if ( FAILED( ::SHGetDesktopFolder( &pDesktop ) ) )
        goto error;

    //
    // ParseDisplayName() wants UTF-16, so convert the path first.
    //
    WCHAR wPath[ MAX_PATH ];
    if ( !LC_toWCHAR( cPath, wPath, sizeof wPath ) )
        goto error;

    result = pDesktop->ParseDisplayName( NULL, NULL, wPath, NULL, &pidl, NULL );
    if ( FAILED( result ) )
        goto error;

    //
    // Binding the path of what we want relative to the Desktop gets us the
    // PIDL for the path of the saved search file.
    //
    result = pDesktop->BindToObject(
        pidl, NULL, IID_IShellFolder,
        reinterpret_cast<void**>( &cSavedSearch->m_pFolder )
    );
    if ( FAILED( result ) )
        goto error;

    //
    // We can now start the enumeration of the saved search file which runs the
    // search.
    //
    result = cSavedSearch->m_pFolder->EnumObjects(
        NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &cSavedSearch->m_pEnumIDList
    );
    if ( result == S_FALSE || FAILED( result ) )
        goto error;

    goto done;

error:
    error = true;
done:
    if ( pDesktop )
        pDesktop->Release();
    if ( cSavedSearch && cSavedSearch->m_pMalloc && pidl )
        cSavedSearch->m_pMalloc->Free( pidl );
    if ( error ) {
        delete cSavedSearch;
        return 0;
    }
    return reinterpret_cast<jlong>( cSavedSearch );
}
Пример #8
0
// full qualified PIDL -> IShellFolder, PIDL
xpr_bool_t Pidl::getSimplePidl(LPCITEMIDLIST aFullPidl, LPSHELLFOLDER &aShellFolder, LPCITEMIDLIST &aSimplePidl)
{
    if (XPR_IS_NULL(aFullPidl))
    {
        return XPR_FALSE;
    }

    LPSHELLFOLDER sShellFolder = XPR_NULL;
    LPITEMIDLIST  sSimplePidl  = XPR_NULL;
    HRESULT       sComResult     = E_FAIL;

    if (Pidl::isSimplePidl(aFullPidl) == XPR_TRUE)
    {
        LPITEMIDLIST sChildPidl;

        sChildPidl = Pidl::findLastItem(aFullPidl);

        sComResult = ::SHGetDesktopFolder((LPSHELLFOLDER *)&sShellFolder);
        if (SUCCEEDED(sComResult))
        {
            sSimplePidl = sChildPidl;
        }
    }
    else
    {
        LPSHELLFOLDER sDesktopShellFolder;
        LPITEMIDLIST  sParentPidl;
        LPITEMIDLIST  sChildPidl;

        sChildPidl = Pidl::findLastItem(aFullPidl);

        sParentPidl = Pidl::clone(aFullPidl);

        if (XPR_IS_TRUE(Pidl::removeLastItem(sParentPidl)))
        {
            sComResult = ::SHGetDesktopFolder(&sDesktopShellFolder);
            if (SUCCEEDED(sComResult))
            {
                sComResult = sDesktopShellFolder->BindToObject(
                    sParentPidl,
                    XPR_NULL,
                    IID_IShellFolder,
                    (LPVOID *)&sShellFolder);

                if (SUCCEEDED(sComResult))
                {
                    sSimplePidl = sChildPidl;
                }

                COM_RELEASE(sDesktopShellFolder);
            }
        }

        COM_FREE(sParentPidl);
    }

    if (XPR_IS_NULL(sSimplePidl))
    {
        COM_RELEASE(sShellFolder);

        return XPR_FALSE;
    }

    if (XPR_IS_NULL(sShellFolder))
    {
        return XPR_FALSE;
    }

    aShellFolder = sShellFolder;
    aSimplePidl  = sSimplePidl;

    return XPR_TRUE;
}
Пример #9
0
int DriveBox_Fill(HWND hwnd) {

    LPSHELLFOLDER lpsfDesktop;
    LPSHELLFOLDER lpsf; // Workspace == CSIDL_DRIVES

    LPITEMIDLIST pidl;
    LPITEMIDLIST pidlEntry;

    LPENUMIDLIST lpe;

    COMBOBOXEXITEM cbei;
    LPDC_ITEMDATA lpdcid;

    ULONG dwAttributes = 0;

    DWORD grfFlags = SHCONTF_FOLDERS;

    // Init ComboBox
    SendMessage(hwnd, WM_SETREDRAW, 0, 0);
    SendMessage(hwnd, CB_RESETCONTENT, 0, 0);

    ZeroMemory(&cbei, sizeof(COMBOBOXEXITEM));
    cbei.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_LPARAM;
    cbei.pszText = LPSTR_TEXTCALLBACK;
    cbei.cchTextMax = MAX_PATH;
    cbei.iImage = I_IMAGECALLBACK;
    cbei.iSelectedImage = I_IMAGECALLBACK;

    // Get pidl to [My Computer]
    if (NOERROR == SHGetSpecialFolderLocation(hwnd, CSIDL_DRIVES, &pidl)) {

        // Get Desktop Folder
        if (NOERROR == SHGetDesktopFolder(&lpsfDesktop)) {

            // Bind pidl to IShellFolder
            if (NOERROR == lpsfDesktop->BindToObject(pidl, NULL, IID_IShellFolder, (void**)&lpsf)) {

                // Create an Enumeration object for lpsf
                if (NOERROR == lpsf->EnumObjects(hwnd, grfFlags, &lpe)) {

                    // Enumerate the contents of [My Computer]
                    while (NOERROR == lpe->Next(1, &pidlEntry, NULL)) {

                        // Add item to the List if it is part of the
                        // Filesystem
                        dwAttributes = SFGAO_FILESYSTEM;

                        lpsf->GetAttributesOf(1, (LPCITEMIDLIST*)&pidlEntry, &dwAttributes);

                        if (dwAttributes & SFGAO_FILESYSTEM) {

                            // Windows XP: check if pidlEntry is a drive
                            SHDESCRIPTIONID di;
                            HRESULT hr;
                            hr = SHGetDataFromIDList(lpsf, pidlEntry, SHGDFIL_DESCRIPTIONID, &di,
                                                     sizeof(SHDESCRIPTIONID));
                            if (hr != NOERROR || (di.dwDescriptionId >= SHDID_COMPUTER_DRIVE35 &&
                                                  di.dwDescriptionId <= SHDID_COMPUTER_OTHER)) {

                                lpdcid = (DC_ITEMDATA*)CoTaskMemAlloc(sizeof(DC_ITEMDATA));

                                // lpdcid->pidl = IL_Copy(pidlEntry);
                                lpdcid->pidl = pidlEntry;
                                lpdcid->lpsf = lpsf;

                                lpsf->AddRef();

                                // Insert sorted ...
                                {
                                    COMBOBOXEXITEM cbei2;
                                    LPDC_ITEMDATA lpdcid2;
                                    HRESULT hr;
                                    cbei2.mask = CBEIF_LPARAM;
                                    cbei2.iItem = 0;

                                    while ((SendMessage(hwnd, CBEM_GETITEM, 0, (LPARAM)&cbei2))) {
                                        lpdcid2 = (LPDC_ITEMDATA)cbei2.lParam;
                                        hr = (lpdcid->lpsf->CompareIDs(0, lpdcid->pidl,
                                                                       lpdcid2->pidl));

                                        if ((short)(SCODE_CODE(GetScode(hr))) < 0)
                                            break;
                                        else
                                            cbei2.iItem++;
                                    }

                                    cbei.iItem = cbei2.iItem;
                                    cbei.lParam = (LPARAM)lpdcid;
                                    SendMessage(hwnd, CBEM_INSERTITEM, 0, (LPARAM)&cbei);
                                }
                            }
                        }

                    } // IEnumIDList::Next()

                    lpe->Release();

                } // IShellFolder::EnumObjects()

                lpsf->Release();

            } // IShellFolder::BindToObject()

            CoTaskMemFree(pidl);

        } // SHGetSpecialFolderLocation()

        lpsfDesktop->Release();

    } // SHGetDesktopFolder()

    SendMessage(hwnd, WM_SETREDRAW, 1, 0);
    // Return number of items added to combo box
    return ((int)SendMessage(hwnd, CB_GETCOUNT, 0, 0));
}
Пример #10
0
//  Snapshots a directory and displays the items in the listview control
int DirList_Fill(HWND hwnd, const WCHAR* lpszDir, DWORD grfFlags, const WCHAR* lpszFileSpec,
                 BOOL bExcludeFilter, BOOL bNoFadeHidden, int iSortFlags, BOOL fSortRev) {

    WCHAR wszDir[MAX_PATH];

    LPSHELLFOLDER lpsfDesktop = NULL;
    LPSHELLFOLDER lpsf = NULL;

    LPITEMIDLIST pidl = NULL;
    LPITEMIDLIST pidlEntry = NULL;

    LPENUMIDLIST lpe = NULL;

    LV_ITEM lvi;
    LPLV_ITEMDATA lplvid;

    ULONG chParsed = 0;
    ULONG dwAttributes = 0;

    DL_FILTER dlf;
    SHFILEINFO shfi = { 0 };

    DLDATA* lpdl = (DLDATA*)GetProp(hwnd, pDirListProp);

    // Initialize default icons
    SHGetFileInfo(L"Icon", FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(SHFILEINFO),
                  SHGFI_USEFILEATTRIBUTES | SHGFI_SMALLICON | SHGFI_SYSICONINDEX);
    lpdl->iDefIconFolder = shfi.iIcon;

    SHGetFileInfo(L"Icon", FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(SHFILEINFO),
                  SHGFI_USEFILEATTRIBUTES | SHGFI_SMALLICON | SHGFI_SYSICONINDEX);
    lpdl->iDefIconFile = shfi.iIcon;

    // First of all terminate running icon thread
    DirList_TerminateIconThread(hwnd);

    // A Directory is strongly required
    if (!lpszDir || !*lpszDir)
        return (-1);

    lstrcpy(lpdl->szPath, lpszDir);

    // Init ListView
    SendMessage(hwnd, WM_SETREDRAW, 0, 0);
    ListView_DeleteAllItems(hwnd);

    // Init Filter
    DirList_CreateFilter(&dlf, lpszFileSpec, bExcludeFilter);

    // Init lvi
    lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
    lvi.iItem = 0;
    lvi.iSubItem = 0;
    lvi.pszText = LPSTR_TEXTCALLBACK;
    lvi.cchTextMax = MAX_PATH;
    lvi.iImage = I_IMAGECALLBACK;

    // Convert Directory to a UNICODE string
    /*MultiByteToWideChar(CP_ACP,
                        MB_PRECOMPOSED,
                        lpszDir,
                        -1,
                        wszDir,
                        MAX_PATH);*/
    lstrcpy(wszDir, lpszDir);

    // Get Desktop Folder
    if (NOERROR == SHGetDesktopFolder(&lpsfDesktop)) {

        // Convert wszDir into a pidl
        if (NOERROR ==
            lpsfDesktop->ParseDisplayName(hwnd, NULL, wszDir, &chParsed, &pidl, &dwAttributes)) {

            // Bind pidl to IShellFolder
            if (NOERROR == lpsfDesktop->BindToObject(pidl, NULL, IID_IShellFolder, (void**)&lpsf)) {

                // Create an Enumeration object for lpsf
                if (NOERROR == lpsf->EnumObjects(hwnd, grfFlags, &lpe)) {

                    // Enumerate the contents of lpsf
                    while (NOERROR == lpe->Next(1, &pidlEntry, NULL)) {

                        // Add found item to the List
                        // Check if it's part of the Filesystem
                        dwAttributes = SFGAO_FILESYSTEM | SFGAO_FOLDER;

                        lpsf->GetAttributesOf(1, (LPCITEMIDLIST*)pidlEntry, &dwAttributes);

                        if (dwAttributes & SFGAO_FILESYSTEM) {

                            // Check if item matches specified filter
                            if (DirList_MatchFilter(lpsf, pidlEntry, &dlf)) {

                                lplvid = (LV_ITEMDATA*)CoTaskMemAlloc(sizeof(LV_ITEMDATA));

                                lplvid->pidl = pidlEntry;
                                lplvid->lpsf = lpsf;

                                lpsf->AddRef();

                                lvi.lParam = (LPARAM)lplvid;

                                // Setup default Icon - Folder or File
                                lvi.iImage = (dwAttributes & SFGAO_FOLDER) ? lpdl->iDefIconFolder
                                                                           : lpdl->iDefIconFile;

                                ListView_InsertItem(hwnd, &lvi);

                                lvi.iItem++;
                            }
                        }

                    } // IEnumIDList::Next()

                    lpe->Release();

                } // IShellFolder::EnumObjects()

            } // IShellFolder::BindToObject()

        } // IShellFolder::ParseDisplayName()

        lpsfDesktop->Release();

    } // SHGetDesktopFolder()

    if (lpdl->pidl)
        CoTaskMemFree(lpdl->pidl);

    if (lpdl->lpsf)
        lpdl->lpsf->Release();

    // Set lpdl
    lpdl->cbidl = IL_GetSize(pidl);
    lpdl->pidl = pidl;
    lpdl->lpsf = lpsf;
    lpdl->bNoFadeHidden = bNoFadeHidden;

    // Set column width to fit window
    ListView_SetColumnWidth(hwnd, 0, LVSCW_AUTOSIZE_USEHEADER);

    // Sort before display is updated
    DirList_Sort(hwnd, iSortFlags, fSortRev);

    // Redraw Listview
    SendMessage(hwnd, WM_SETREDRAW, 1, 0);

    // Return number of items in the control
    return (ListView_GetItemCount(hwnd));
}