当前位置: 首页>>代码示例>>C++>>正文


C++ IShellItemArray::GetCount方法代码示例

本文整理汇总了C++中IShellItemArray::GetCount方法的典型用法代码示例。如果您正苦于以下问题:C++ IShellItemArray::GetCount方法的具体用法?C++ IShellItemArray::GetCount怎么用?C++ IShellItemArray::GetCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IShellItemArray的用法示例。


在下文中一共展示了IShellItemArray::GetCount方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CoCreateInstance

std::vector<std::wstring> APlayerWindow::showOpenFile()
{
	HRESULT hr = S_OK;
	std::vector<std::wstring> filePaths;

	IFileOpenDialog *fileDlg = NULL;
	hr = CoCreateInstance(CLSID_FileOpenDialog,
		NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&fileDlg));
	if (FAILED(hr)) return filePaths;
	ON_SCOPE_EXIT([&] { fileDlg->Release(); });

	IKnownFolderManager *pkfm = NULL;
	hr = CoCreateInstance(CLSID_KnownFolderManager,
		NULL,
		CLSCTX_INPROC_SERVER,
		IID_PPV_ARGS(&pkfm));
	if (FAILED(hr)) return filePaths;
	ON_SCOPE_EXIT([&] { pkfm->Release(); });

	IKnownFolder *pKnownFolder = NULL;
	hr = pkfm->GetFolder(FOLDERID_PublicMusic, &pKnownFolder);
	if (FAILED(hr)) return filePaths;
	ON_SCOPE_EXIT([&] { pKnownFolder->Release(); });

	IShellItem *psi = NULL;
	hr = pKnownFolder->GetShellItem(0, IID_PPV_ARGS(&psi));
	if (FAILED(hr)) return filePaths;
	ON_SCOPE_EXIT([&] { psi->Release(); });

	hr = fileDlg->AddPlace(psi, FDAP_BOTTOM);
	COMDLG_FILTERSPEC rgSpec[] = {
		{ L"ÒôÀÖÎļþ", SupportType }
	};
	fileDlg->SetFileTypes(1, rgSpec);

	DWORD dwOptions;
	fileDlg->GetOptions(&dwOptions);
	fileDlg->SetOptions(dwOptions | FOS_ALLOWMULTISELECT);
	hr = fileDlg->Show(NULL);
	if (SUCCEEDED(hr)) {
		IShellItemArray *pRets;
		hr = fileDlg->GetResults(&pRets);
		if (SUCCEEDED(hr)) {
			DWORD count;
			pRets->GetCount(&count);
			for (DWORD i = 0; i < count; i++) {
				IShellItem *pRet;
				LPWSTR nameBuffer;
				pRets->GetItemAt(i, &pRet);
				pRet->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &nameBuffer);
				filePaths.push_back(std::wstring(nameBuffer));
				pRet->Release();
				CoTaskMemFree(nameBuffer);
			}
			pRets->Release();
		}
	}
	return filePaths;
}
开发者ID:wyrover,项目名称:MusicPlayer,代码行数:59,代码来源:APlayerWindow.cpp

示例2: fileOpenDialog

extern "C" LXCWIN_API HRESULT fileOpenDialog(HWND hWnd, DWORD *count, LPWSTR **result) {
    *result = NULL;
    HRESULT hr = S_OK;
    CoInitialize(nullptr);
    IFileOpenDialog *pfd = NULL;
    hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
    if (SUCCEEDED(hr)) {
        // set default folder to "My Documents"
        IShellItem *psiDocuments = NULL;
        hr = SHCreateItemInKnownFolder(FOLDERID_Documents, 0, NULL,
                                       IID_PPV_ARGS(&psiDocuments));
        if (SUCCEEDED(hr)) {
            hr = pfd->SetDefaultFolder(psiDocuments);
            psiDocuments->Release();
        }

        // dialog title
        pfd->SetTitle(L"Select files to share");

        // allow multiselect, restrict to real files
        DWORD dwOptions;
        hr = pfd->GetOptions(&dwOptions);
        if (SUCCEEDED(hr)) {
            // ideally, allow selecting folders as well as files, but IFileDialog does not support this :(
            pfd->SetOptions(dwOptions | FOS_ALLOWMULTISELECT | FOS_FORCEFILESYSTEM); // | FOS_PICKFOLDERS
        }

        // do not limit to certain file types

        // show the open file dialog
        hr = pfd->Show(hWnd);
        if (SUCCEEDED(hr)) {
            IShellItemArray *psiaResults;
            hr = pfd->GetResults(&psiaResults);
            if (SUCCEEDED(hr)) {
                hr = psiaResults->GetCount(count);
                if (SUCCEEDED(hr)) {
                    *result = (LPWSTR*)calloc(*count, sizeof(LPWSTR));
                    if (*result != NULL) {
                        for (DWORD i = 0; i < *count; i++) {
                            IShellItem *resultItem = NULL;
                            hr = psiaResults->GetItemAt(i, &resultItem);
                            if (SUCCEEDED(hr)) {
                                resultItem->GetDisplayName(SIGDN_FILESYSPATH, &((*result)[i]));
                                resultItem->Release();
                            }
                        }
                        // paths now contains selected files
                    }
                }
                psiaResults->Release();
            }
        }
        pfd->Release();
    }
    return hr;
}
开发者ID:tfg13,项目名称:LanXchange,代码行数:57,代码来源:lxcwin.cpp

示例3: v_ExecuteLibCommand

    HRESULT v_ExecuteLibCommand()
    {
        // Get the private and public save locations.
        IShellItem *psiPrivateSaveLoc;
        HRESULT hr = _plib->GetDefaultSaveFolder(DSFT_PRIVATE, IID_PPV_ARGS(&psiPrivateSaveLoc));
        if (SUCCEEDED(hr))
        {
            IShellItem *psiPublicSaveLoc;
            hr = _plib->GetDefaultSaveFolder(DSFT_PUBLIC, IID_PPV_ARGS(&psiPublicSaveLoc));
            if (SUCCEEDED(hr))
            {
                // Get the list of folders that match the specified filter.
                IShellItemArray *psiaFolders;
                hr = _plib->GetFolders(_lffFilter, IID_PPV_ARGS(&psiaFolders));
                if (SUCCEEDED(hr))
                {
                    DWORD cFolders;
                    hr = psiaFolders->GetCount(&cFolders);
                    if (SUCCEEDED(hr))
                    {
                        Output(L"Library contains %u folders:\n", cFolders);
                        for (DWORD iFolder = 0; iFolder < cFolders; iFolder++)
                        {
                            IShellItem *psiFolder;
                            if (SUCCEEDED(psiaFolders->GetItemAt(iFolder, &psiFolder)))
                            {
                                // Print each folder's name as an absolute path, suitable for parsing in the Shell Namespace (e.g SHParseDisplayName).
                                // For file system folders (the typical case), this will be the file system path of the folder.
                                PWSTR pszDisplay;
                                if (SUCCEEDED(psiFolder->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &pszDisplay)))
                                {
                                    PCWSTR pszPrefix = L"  ";
                                    int iCompare;
                                    if (S_OK == psiPrivateSaveLoc->Compare(psiFolder, SICHINT_CANONICAL | SICHINT_TEST_FILESYSPATH_IF_NOT_EQUAL, &iCompare))
                                    {
                                        pszPrefix = L"* ";
                                    }
                                    else if (S_OK == psiPublicSaveLoc->Compare(psiFolder, SICHINT_CANONICAL | SICHINT_TEST_FILESYSPATH_IF_NOT_EQUAL, &iCompare))
                                    {
                                        pszPrefix = L"# ";
                                    }

                                    Output(L"%s%s\n", pszPrefix, pszDisplay);
                                    CoTaskMemFree(pszDisplay);
                                }
                                psiFolder->Release();
                            }
                        }
                    }
                    psiaFolders->Release();
                }
                psiPublicSaveLoc->Release();
            }
            psiPrivateSaveLoc->Release();
        }
        return hr;
    }
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:57,代码来源:ShellLibraryCommandLine.cpp

示例4: OnFileOk

STDMETHODIMP COpenFileListener::OnFileOk(IFileDialog* pfd)
{
	IShellItemArray *psiaResults;
	IFileDialogCustomize *pfdc;
	HRESULT hr;
	IFileOpenDialog *fod;
	FILEINFO fileinfoTmp = {0};
	DWORD choice;

	fileinfoTmp.parentList = pFInfoList;

	hr = pfd->QueryInterface(IID_PPV_ARGS(&fod));

	if(SUCCEEDED(hr)) {
		hr = fod->GetSelectedItems(&psiaResults);

		if (SUCCEEDED(hr)) {
			DWORD fileCount;
			IShellItem *isi;
			LPWSTR pwsz = NULL;

			psiaResults->GetCount(&fileCount);
			for(DWORD i=0;i<fileCount;i++) {
				psiaResults->GetItemAt(i,&isi);
				isi->GetDisplayName(SIGDN_FILESYSPATH,&pwsz);
				isi->Release();
                fileinfoTmp.szFilename = pwsz;
				pFInfoList->fInfos.push_back(fileinfoTmp);
				CoTaskMemFree(pwsz);
			}
			psiaResults->Release();
		}
		fod->Release();
	}

	hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdc));

	if(SUCCEEDED(hr)) {
		hr = pfdc->GetSelectedControlItem(FDIALOG_OPENCHOICES,&choice);
		if(SUCCEEDED(hr)) {
			if(choice==FDIALOG_CHOICE_REPARENT) {
				pFInfoList->uiCmdOpts = CMD_REPARENT;
			}
            else if(choice==FDIALOG_CHOICE_ALLHASHES) {
                pFInfoList->uiCmdOpts = CMD_ALLHASHES;
            }
            else if(choice==FDIALOG_CHOICE_BSD) {
                pFInfoList->uiCmdOpts = CMD_FORCE_BSD;
            }
		}

		pfdc->Release();
	}

	return S_OK;
}
开发者ID:KagamiChan,项目名称:RapidCRC-Unicode,代码行数:56,代码来源:COpenFileListener.cpp

示例5: GetShellItem

// Populates item. It is the responsibility of the caller to call item->Release()
// if the return value indicates success
HRESULT ComposerShellMenu::GetShellItem(IShellItem ** item, PBOOLEAN isFile)
{
    HRESULT hr = E_FAIL;
    *item = NULL;
        
    if (m_Folder)
    {
        hr = SHCreateItemFromIDList(m_Folder, IID_PPV_ARGS(item));
    }
    else if (m_Data)
    {
        IShellItemArray *itemArray = NULL;
        hr = SHCreateShellItemArrayFromDataObject(m_Data, IID_PPV_ARGS(&itemArray));
        
        if (SUCCEEDED(hr))
        {
            DWORD count = 0;
            hr = itemArray->GetCount(&count);           
            
            if (SUCCEEDED(hr))
            {
                if (1 == count)
                {
                    hr = itemArray->GetItemAt(0, item);
                }
                else
                {
                    hr = E_FAIL;
                }
            }
            
            itemArray->Release();
            itemArray = NULL;
        }
    }

    if (SUCCEEDED(hr))
    {
        hr = IsShellItemValid(*item, false, isFile);

        if (FAILED(hr))
        {
            (*item)->Release();
            *item = NULL;
        }
    }

    return hr;
}
开发者ID:AlexRee,项目名称:windows-setup,代码行数:51,代码来源:menu.cpp

示例6: PyCom_BuildPyException

// @pymethod |PyIShellItemArray|GetCount|Description of GetCount.
PyObject *PyIShellItemArray::GetCount(PyObject *self, PyObject *args)
{
	IShellItemArray *pISIA = GetI(self);
	if ( pISIA == NULL )
		return NULL;
	if ( !PyArg_ParseTuple(args, ":GetCount") )
		return NULL;
	HRESULT hr;
	DWORD dwNumItems;
	PY_INTERFACE_PRECALL;
	hr = pISIA->GetCount( &dwNumItems );
	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pISIA, IID_IShellItemArray );
	return PyInt_FromLong(dwNumItems);
}
开发者ID:,项目名称:,代码行数:18,代码来源:

示例7: p

std::vector<fs::path> open_file_dialog::get_paths()
{
    IShellItemArray *items = NULL;
    dlg_->GetResults(&items);

    if (items == NULL)
    {
        return std::vector<fs::path>();
    }

    DWORD count;
    items->GetCount(&count);

    std::vector<fs::path> paths;

    for (DWORD i = 0; i < count; i++)
    {
        IShellItem* item = NULL;
        items->GetItemAt(i, &item);

        PWSTR path = NULL;
        HRESULT res = item->GetDisplayName(SIGDN_FILESYSPATH, &path);

        if (res != S_OK)
        {
            LOG(warning) << "Could not get display name from path: " << std::hex << res;
            continue;
        }

        fs::path p(path);
        paths.push_back(p);

        CoTaskMemFree(path);
        item->Release();
    }

    items->Release();

    return paths;
}
开发者ID:Awa128,项目名称:picotorrent,代码行数:40,代码来源:open_file_dialog.cpp

示例8: GetSelectedItems

BOOL GetSelectedItems(IFileDialog *fd, vector<Wstr> *res)
{
	IFolderView2 *fv = NULL;
	if (FAILED(IUnknown_QueryService(fd, SID_SFolderView, IID_PPV_ARGS(&fv)))) return FALSE;
	scope_defer([&](){ fv->Release(); });

	IShellItemArray *sia = NULL;
	if (FAILED(fv->GetSelection(TRUE, &sia))) return FALSE;
	scope_defer([&](){ sia->Release(); });

	DWORD	num = 0;
	if (FAILED(sia->GetCount(&num))) return FALSE;

	for (DWORD i=0; i < num; i++) {
		IShellItem	*si = NULL;

		if (FAILED(sia->GetItemAt(i, &si))) return FALSE;
		scope_defer([&](){ si->Release(); });

//		LPITEMIDLIST	idl;
//		DWORD			val = 0;
//		if (SUCCEEDED(::SHGetIDListFromObject(si, &idl))) {
//			PITEMID_CHILD ic = ILFindLastID(idl);
//			HRESULT hr = fv->GetSelectionState(ic, &val);
//			DBG("hr=%x val=%x\n", hr, val);
//		}

		PWSTR path = NULL;
		if (FAILED(si->GetDisplayName(SIGDN_FILESYSPATH, &path))) continue;
		scope_defer([&](){ ::CoTaskMemFree(path); });

		res->push_back(path);
		DBGW(L"path=%s\n", path);
	}
	return	TRUE;
}
开发者ID:Mapaler,项目名称:FastCopy-M,代码行数:36,代码来源:tcmndlg.cpp

示例9: qt_win_CID_get_open_file_names

QStringList qt_win_CID_get_open_file_names(const QFileDialogArgs &args,
                                       QString *initialDirectory,
                                       const QStringList &filterList,
                                       QString *selectedFilter,
                                       int selectedFilterIndex)
{
    QStringList result;
    QDialog modal_widget;
    modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true);
    modal_widget.setParent(args.parent, Qt::Window);
    QApplicationPrivate::enterModal(&modal_widget);
    // Multiple selection is allowed only in IFileOpenDialog.
    IFileOpenDialog *pfd = 0;
    HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
                                  NULL,
                                  CLSCTX_INPROC_SERVER,
                                  IID_PPV_ARGS(&pfd));

    if (SUCCEEDED(hr)) {
        qt_win_set_IFileDialogOptions(pfd, args.selection,
                                      args.directory, args.caption,
                                      filterList, QFileDialog::ExistingFiles,
                                      args.options);
        // Set the currently selected filter (one-based index).
        hr = pfd->SetFileTypeIndex(selectedFilterIndex+1);
        QWidget *parentWindow = args.parent;
        if (parentWindow)
            parentWindow = parentWindow->window();
        else
            parentWindow = QApplication::activeWindow();
        // Show the file dialog.
        hr = pfd->Show(parentWindow ? parentWindow->winId() : 0);
        if (SUCCEEDED(hr)) {
            // Retrieve the results.
            IShellItemArray *psiaResults;
            hr = pfd->GetResults(&psiaResults);
            if (SUCCEEDED(hr)) {
                DWORD numItems = 0;
                psiaResults->GetCount(&numItems);
                for (DWORD i = 0; i<numItems; i++) {
                    IShellItem *psi = 0;
                    hr = psiaResults->GetItemAt(i, &psi);
                    if (SUCCEEDED(hr)) {
                        // Retrieve the file name from shell item.
                        wchar_t *pszPath;
                        hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);
                        if (SUCCEEDED(hr)) {
                            QString fileName = QString::fromWCharArray(pszPath);
                            result.append(fileName);
                            CoTaskMemFree(pszPath);
                        }
                        psi->Release(); // Free the current item.
                    }
                }
                psiaResults->Release(); // Free the array of items.
            }
        }
    }
    QApplicationPrivate::leaveModal(&modal_widget);

    qt_win_eatMouseMove();

    if (!result.isEmpty()) {
        // Retrieve the current folder name.
        IShellItem *psi = 0;
        hr = pfd->GetFolder(&psi);
        if (SUCCEEDED(hr)) {
            wchar_t *pszPath;
            hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);
            if (SUCCEEDED(hr)) {
                *initialDirectory = QString::fromWCharArray(pszPath);
                CoTaskMemFree(pszPath);
            }
            psi->Release();
        }
        // Retrieve the currently selected filter.
        if (selectedFilter) {
            quint32 filetype = 0;
            hr = pfd->GetFileTypeIndex(&filetype);
            if (SUCCEEDED(hr) && filetype && filetype <= (quint32)filterList.length()) {
                // This is a one-based index, not zero-based.
                *selectedFilter = filterList[filetype-1];
            }
        }
    }
    if (pfd)
        pfd->Release();
    return result;
}
开发者ID:Nacto1,项目名称:qt-everywhere-opensource-src-4.6.2,代码行数:89,代码来源:qfiledialog_win.cpp

示例10: showDirDialog

QStringList showDirDialog(IFileOpenDialog* pDialog, QWidget* parent)
{
    Q_ASSERT(pDialog != NULL);

    QStringList Result;

    if (parent == NULL)
        parent = QApplication::activeWindow();
    HWND hwndParent = parent ? parent->window()->winId() : NULL;

    HRESULT HResult = pDialog->Show(hwndParent);
    if (SUCCEEDED(HResult))
    {
        // Что-то было выбрано.
        IShellItemArray* pShellItemArray;
        HResult = pDialog->GetResults(&pShellItemArray);
        if (SUCCEEDED(HResult))
        {
            DWORD ItemsCount;
            HResult = pShellItemArray->GetCount(&ItemsCount);
            if (SUCCEEDED(HResult))
            {
                IShellItem* pItem;
                for (DWORD i = 0; i < ItemsCount; ++i)
                {
                    HResult = pShellItemArray->GetItemAt(i, &pItem);
                    if (SUCCEEDED(HResult))
                    {
                        wchar_t* lpwName;
                        HResult = pItem->GetDisplayName(SIGDN_FILESYSPATH, &lpwName);
                        if (SUCCEEDED(HResult))
                        {
                            Result.append(QString::fromWCharArray(lpwName));
                            CoTaskMemFree(lpwName);
                        }
                        else {
                            qWarning("IShellItem::GetDisplayName error: %s.",
                                     qPrintable(GetSystemErrorString(HResult)));
                        }
                        pItem->Release();
                    }
                    else {
                        qWarning("IShellItemArray::GetItemAt(%lu, ...) error: %s.",
                                 i, qPrintable(GetSystemErrorString(HResult)));
                    }
                }
                pShellItemArray->Release();
            }
            else {
                qWarning("IShellItemArray::GetCount error: %s",
                         qPrintable(GetSystemErrorString(HResult)));
            }
        }
        else {
            qWarning("IFileOpenDialog::GetResults error: %s",
                     qPrintable(GetSystemErrorString(HResult)));
        }
    }
    else {
        if (HResult == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
            // Пользователь ничего не выбрал.
        }
        else {
            qWarning("IFileOpenDialog::Show error: %s",
                     qPrintable(GetSystemErrorString(HResult)));
        }
    }

    return Result;
}
开发者ID:danielhuang2005,项目名称:MultiCopy,代码行数:70,代码来源:FileDialogs_win.cpp

示例11: runModalInternal

//-----------------------------------------------------------------------------
bool VistaFileSelector::runModalInternal ()
{
	fileDialog = 0;
	HRESULT hr = -1;
	if (style == kSelectSaveFile)
	{
		hr = CoCreateInstance (CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IFileDialog, &fileDialog));
		if (defaultSaveName)
		{
			fileDialog->SetFileName (UTF8StringHelper (defaultSaveName));
		}
	}
	else
	{
		hr = CoCreateInstance (CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IFileDialog, &fileDialog));
		if (SUCCEEDED (hr))
		{
			if (style == kSelectDirectory)
			{
				DWORD dwOptions = 0;
				hr = fileDialog->GetOptions (&dwOptions);
				if (SUCCEEDED (hr))
					hr = fileDialog->SetOptions (dwOptions | FOS_PICKFOLDERS);
				if (FAILED (hr))
				{
					fileDialog->Release ();
					fileDialog = 0;
					return false;
				}
			}
			if (allowMultiFileSelection)
			{
				DWORD dwOptions = 0;
				hr = fileDialog->GetOptions (&dwOptions);
				if (SUCCEEDED (hr))
					hr = fileDialog->SetOptions (dwOptions | FOS_ALLOWMULTISELECT);
				if (FAILED (hr))
				{
					fileDialog->Release ();
					fileDialog = 0;
					return false;
				}
			}
		}
	}
	if (FAILED (hr))
	{
		fileDialog = 0;
		return false;
	}

	if (title)
		hr = fileDialog->SetTitle (UTF8StringHelper (title));

	DWORD numExtensions = 0;
	DWORD defaultFileTypeIndex = 0;
	COMDLG_FILTERSPEC* filters = buildExtensionFilter (extensions, defaultExtension, numExtensions, defaultFileTypeIndex);
	if (filters)
	{
		fileDialog->SetFileTypes (numExtensions, filters);
		if (defaultFileTypeIndex)
			fileDialog->SetFileTypeIndex (defaultFileTypeIndex);
	}
	if (initialPath && _SHCreateItemFromParsingName)
	{
		IShellItem* shellItem;
		hr = _SHCreateItemFromParsingName (UTF8StringHelper (initialPath), 0, IID_PPV_ARG (IShellItem, &shellItem));
		if (SUCCEEDED (hr))
		{
			fileDialog->SetFolder (shellItem);
			shellItem->Release ();
		}
	}
	Win32Frame* win32Frame = frame->getPlatformFrame () ? dynamic_cast<Win32Frame*> (frame->getPlatformFrame ()) : 0;
	hr = fileDialog->Show (win32Frame ? win32Frame->getPlatformWindow () : 0);
	if (SUCCEEDED (hr))
	{
		if (allowMultiFileSelection)
		{
			IFileOpenDialog* openFileDialog = 0;
			hr = fileDialog->QueryInterface (IID_PPV_ARG(IFileOpenDialog, &openFileDialog));
			if (SUCCEEDED (hr))
			{
				IShellItemArray* items;
				hr = openFileDialog->GetResults (&items);
				if (SUCCEEDED (hr))
				{
					DWORD count;
					hr = items->GetCount (&count);
					for (DWORD i = 0; i < count; i++)
					{
						IShellItem* item;
						hr = items->GetItemAt (i, &item);
						if (SUCCEEDED (hr))
						{
							LPWSTR filesysPath = 0;
							hr = item->GetDisplayName (SIGDN_FILESYSPATH, &filesysPath);
							if (SUCCEEDED (hr))
							{
//.........这里部分代码省略.........
开发者ID:Piticfericit,项目名称:vstgui,代码行数:101,代码来源:winfileselector.cpp

示例12: ShareWithBoxItems

HRESULT ContextMenu::ShareWithBoxItems(IDataObject *dataObject, HWND hwndParent)
{
	HRESULT hr = S_OK;

    if (dataObject == NULL) 
    {
		return E_FAIL;
	}

	m_paths.clear();

#if (WINVER >= 0x0600)
	IShellItemArray *psia;
	hr = SHCreateShellItemArrayFromDataObject(dataObject, IID_PPV_ARGS(&psia));
	if (SUCCEEDED(hr))
	{
		//hr = DisplayItems(psia, hwndParent);
	
		DWORD count;
		psia->GetCount(&count);

		for(DWORD i = 0; i < count; ++i)
		{
			IShellItem *psi;
			hr = psia->GetItemAt(i, &psi);
			if (SUCCEEDED(hr))
			{
				PWSTR pszDisplayName;
				hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &pszDisplayName);
				if (SUCCEEDED(hr))
				{
					m_paths.push_back(wcsdup(pszDisplayName));
					CoTaskMemFree(pszDisplayName);
				}
				psi->Release();
			}
			else
			{
				break;
			}
		}  
		psia->Release();      
	}
#else
	STGMEDIUM   medium;
    FORMATETC   fe = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};

	if(SUCCEEDED(dataObject->GetData(&fe, &medium)))
	{
		// Get the count of files dropped.
		UINT uCount = DragQueryFile((HDROP)medium.hGlobal, (UINT)-1, NULL, 0);

		// Get the first file name from the CF_HDROP.
		for(UINT i = 0; i < uCount; ++i)
		{
			WCHAR fileName[MAX_PATH];
			if(DragQueryFileW((HDROP)medium.hGlobal, i, fileName, MAX_PATH))
			{
					m_paths.push_back(wcsdup(fileName));
			}
        }

		ReleaseStgMedium(&medium);
    }
#endif
	ShareWithBox(hwndParent);

    return hr;
}
开发者ID:UrsusHorribilis,项目名称:simpleshare,代码行数:69,代码来源:contextmenu.cpp


注:本文中的IShellItemArray::GetCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。