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


C++ IShellItem类代码示例

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


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

示例1: SetDefaultPath

static nfdresult_t SetDefaultPath( IFileDialog *dialog, const char *defaultPath )
{
    if ( !defaultPath || strlen(defaultPath) == 0 )
        return NFD_OKAY;

    wchar_t *defaultPathW = {0};
    CopyNFDCharToWChar( defaultPath, &defaultPathW );

    IShellItem *folder;
    HRESULT result = SHCreateItemFromParsingName( defaultPathW, NULL, IID_PPV_ARGS(&folder) );

    // Valid non results.
    if ( result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || result == HRESULT_FROM_WIN32(ERROR_INVALID_DRIVE) )
    {
        NFDi_Free( defaultPathW );
        return NFD_OKAY;
    }

    if ( !SUCCEEDED(result) )
    {
        NFDi_SetError("Error creating ShellItem");
        NFDi_Free( defaultPathW );
        return NFD_ERROR;
    }
    
    // Could also call SetDefaultFolder(), but this guarantees defaultPath -- more consistency across API.
    dialog->SetFolder( folder );

    NFDi_Free( defaultPathW );
    folder->Release();
    
    return NFD_OKAY;
}
开发者ID:kjoshi,项目名称:nativefiledialog,代码行数:33,代码来源:nfd_win.cpp

示例2: fnSHCreateItemFromParsingName

// On Vista or 7 we could use SHIL_JUMBO to get a 256x256 icon,
// but we'll use SHCreateItemFromParsingName as it'll give an identical
// icon to the one shown in explorer and it scales automatically.
bool WinIconProvider::addIconFromShellFactory(QString filePath, QIcon& icon) const
{
	HRESULT hr = S_FALSE;

	if (fnSHCreateItemFromParsingName)
	{
		IShellItem* psi = NULL;
        hr = fnSHCreateItemFromParsingName((PCWSTR)filePath.utf16(), 0, IID_IShellItem, (void**)&psi);
		if (hr == S_OK)
		{
			IShellItemImageFactory* psiif = NULL;
			hr = psi->QueryInterface(IID_IShellItemImageFactory, (void**)&psiif);
			if (hr == S_OK)
			{
				HBITMAP iconBitmap = NULL;
				SIZE iconSize = {preferredSize, preferredSize};
				hr = psiif->GetImage(iconSize, SIIGBF_RESIZETOFIT | SIIGBF_ICONONLY, &iconBitmap);
				if (hr == S_OK)
				{
                    QPixmap iconPixmap = QtWin::fromHBITMAP(iconBitmap);
					icon.addPixmap(iconPixmap);
					DeleteObject(iconBitmap);
				}

				psiif->Release();
			}
			psi->Release();
		}
	}

	return hr == S_OK;
}
开发者ID:Slesa,项目名称:launchy,代码行数:35,代码来源:win_Iconprovider.cpp

示例3: GetI

// @pymethod |PyINameSpaceTreeControl|SetItemCustomState|Description of SetItemCustomState.
PyObject *PyINameSpaceTreeControl::SetItemCustomState(PyObject *self, PyObject *args)
{
	INameSpaceTreeControl *pINSTC = GetI(self);
	if ( pINSTC == NULL )
		return NULL;
	// @pyparm <o PyIShellItem>|psi||Description for psi
	// @pyparm int|iStateNumber||Description for iStateNumber
	PyObject *obpsi;
	IShellItem * psi;
	int iStateNumber;
	if ( !PyArg_ParseTuple(args, "Oi:SetItemCustomState", &obpsi, &iStateNumber) )
		return NULL;
	if (!PyCom_InterfaceFromPyInstanceOrObject(obpsi, IID_IShellItem, (void **)&psi, TRUE /* bNoneOK */))
		return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pINSTC->SetItemCustomState( psi, iStateNumber );
	if (psi) psi->Release();
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pINSTC, IID_INameSpaceTreeControl );
	Py_INCREF(Py_None);
	return Py_None;

}
开发者ID:DavidGuben,项目名称:rcbplayspokemon,代码行数:26,代码来源:PyINameSpaceTreeControl.cpp

示例4: GetI

// @pymethod |PyIShellLibrary|SetDefaultSaveFolder|Sets the default save location
PyObject *PyIShellLibrary::SetDefaultSaveFolder(PyObject *self, PyObject *args)
{
	IShellLibrary *pISL = GetI(self);
	if ( pISL == NULL )
		return NULL;
	DEFAULTSAVEFOLDERTYPE Type;
	IShellItem *SaveFolder;
	PyObject *obSaveFolder;
	// @pyparm int|Type||Specifies public or private save location, shellcon.DSFT_*
	// @pyparm <o PyIShellItem>|SaveFolder||New default location, must be in the library
	if (!PyArg_ParseTuple(args, "iO:SetDefaultSaveFolder", &Type, &obSaveFolder))
		return NULL;
	if (!PyCom_InterfaceFromPyObject(obSaveFolder, IID_IShellItem, (void **)&SaveFolder, FALSE))
		return NULL;

	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pISL->SetDefaultSaveFolder(Type, SaveFolder);
	SaveFolder->Release();
	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pISL, IID_IShellLibrary );
	Py_INCREF(Py_None);
	return Py_None;
}
开发者ID:DavidGuben,项目名称:rcbplayspokemon,代码行数:27,代码来源:PyIShellLibrary.cpp

示例5: PickContainer

void PickContainer()
{
    IFileDialog *pfd;
    if (SUCCEEDED(CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd))))
    {
        DWORD dwOptions;
        if (SUCCEEDED(pfd->GetOptions(&dwOptions)))
        {
            pfd->SetOptions(dwOptions | FOS_PICKFOLDERS);
        }

        if (SUCCEEDED(pfd->Show(NULL)))
        {
            IShellItem *psi;
            if (SUCCEEDED(pfd->GetResult(&psi)))
            {
                PWSTR pszPath;
                if (SUCCEEDED(GetIDListName(psi, &pszPath)))
                {
                    MessageBox(NULL, pszPath, L"Selected Container", MB_OK);
                    CoTaskMemFree(pszPath);
                }
                psi->Release();
            }
        }
        pfd->Release();
    }
}
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:28,代码来源:CommonFileDialogModes.cpp

示例6: GetShellItem

HRESULT ComposerShellMenu::GetTargetData()
{
    IShellItem* item = NULL;
    BOOLEAN isFile = false;
    HRESULT hr = GetShellItem(&item, &isFile);
    
    if (SUCCEEDED(hr))
    {
        if (isFile)
        {
            IShellItem* parent = NULL;
            hr = GetShellItemParent(item, &parent);

            if (SUCCEEDED(hr))
            {
                hr = this->GetDataFromShellItem(parent);
                parent->Release();
            }
        }
        else
        {
            hr = this->GetDataFromShellItem(item);
        }
        
        item->Release();
    }

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

示例7: GetI

// @pymethod interface|PyIShellItem|BindToHandler|Creates an instance of one of the item's handlers
PyObject *PyIShellItem::BindToHandler(PyObject *self, PyObject *args)
{
	IShellItem *pISI = GetI(self);
	if ( pISI == NULL )
		return NULL;
	// @pyparm <o PyIBindCtx>|pbc||Used to pass parameters that influence the binding operation, can be None
	// @pyparm <o PyIID>|bhid||GUID that identifies a handler (shell.BHID_*)
	// @pyparm <o PyIID>|riid||The interface to return
	PyObject *obpbc;
	PyObject *obbhid;
	PyObject *obriid;
	IBindCtx *pbc;
	IID bhid;
	IID riid;
	void *pv;
	if ( !PyArg_ParseTuple(args, "OOO:BindToHandler", &obpbc, &obbhid, &obriid) )
		return NULL;
	if (!PyWinObject_AsIID(obbhid, &bhid))
		return NULL;
	if (!PyWinObject_AsIID(obriid, &riid))
		return NULL;
	if (!PyCom_InterfaceFromPyInstanceOrObject(obpbc, IID_IBindCtx, (void **)&pbc, TRUE /* bNoneOK */))
		return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pISI->BindToHandler( pbc, bhid, riid, &pv );
	if (pbc) pbc->Release();

	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pISI, IID_IShellItem );
	return PyCom_PyObjectFromIUnknown((IUnknown *)pv, riid, FALSE);
}
开发者ID:malrsrch,项目名称:pywin32,代码行数:35,代码来源:PyIShellItem.cpp

示例8: DisplayItems

HRESULT ContextMenu::DisplayItems(IShellItemArray *psia, HWND hwndParent)
{
	DWORD count;
	psia->GetCount(&count);

	for(DWORD i = 0; i < count; ++i)
	{
	    IShellItem *psi;
		HRESULT hr = psia->GetItemAt(i, &psi);
		if (SUCCEEDED(hr))
		{
			PWSTR pszDisplayName;
			hr = psi->GetDisplayName(SIGDN_NORMALDISPLAY, &pszDisplayName);
			if (SUCCEEDED(hr))
			{
				MessageBoxW(hwndParent, pszDisplayName, pszDisplayName, MB_OK);
				CoTaskMemFree(pszDisplayName);
			}
			psi->Release();
		}
		else
		{
			return hr;
		}
    }  

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

示例9: LoadFile

PWSTR LoadFile() {
	IFileOpenDialog *pFileOpen;
	PWSTR pszFilePath = NULL;

	// Create the FileOpenDialog object.
	HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
		IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
	if (SUCCEEDED(hr))
	{
		//IShellItem *psiDocuments = NULL;
		//hr = SHCreateItemInKnownFolder(FOLDERID_Documents, 0, NULL, IID_PPV_ARGS(&psiDocuments));

		//if (SUCCEEDED(hr)) {
		//	hr = pFileOpen->SetFolder(psiDocuments);
		//	psiDocuments->Release();
		//}
		// Show the Open dialog box.
		hr = pFileOpen->Show(NULL);

		// Get the file name from the dialog box.
		if (SUCCEEDED(hr))
		{
			IShellItem *pItem;
			hr = pFileOpen->GetResult(&pItem);
			if (SUCCEEDED(hr))
			{
				hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);

				pItem->Release();
			}
		}
		pFileOpen->Release();
	}
	return pszFilePath;
}
开发者ID:arbiter34,项目名称:Win32NES,代码行数:35,代码来源:Win32NES.cpp

示例10: GetI

// @pymethod (int, <o PyIShellItemResources>)|PyITransferSource|OpenItem|Initiates the copying of an item
PyObject *PyITransferSource::OpenItem(PyObject *self, PyObject *args)
{
	ITransferSource *pITS = GetI(self);
	if ( pITS == NULL )
		return NULL;
	// @pyparm <o PyIShellItem>|Item||The item to be copied.
	TRANSFER_SOURCE_FLAGS flags;
	// @pyparm int|flags||Combination of shellcon.TSF_* flags
	// @pyparm <o PyIID>|riid|IID_IShellItemResources|The interface to return
	void *pv;
	PyObject *obpsi;
	IShellItem * psi;
	IID riid = IID_IShellItemResources;
	if ( !PyArg_ParseTuple(args, "Oi|O&:OpenItem", &obpsi, &flags,
		PyWinObject_AsIID, &riid))
		return NULL;
	if (!PyCom_InterfaceFromPyInstanceOrObject(obpsi, IID_IShellItem, (void **)&psi, FALSE))
		return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pITS->OpenItem( psi, flags, riid, &pv);
	psi->Release();
	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pITS, IID_ITransferSource );
	return Py_BuildValue("lN", hr, PyCom_PyObjectFromIUnknown((IUnknown *)pv, riid, FALSE));
}
开发者ID:DavidGuben,项目名称:rcbplayspokemon,代码行数:29,代码来源:PyITransferSource.cpp

示例11: ChangeDropImageType

	void ChangeDropImageType(DROPIMAGETYPE newType)
	{
		if (newType != _dropImageType) {
			_dropImageType = newType;
			if (_pdtobj != nullptr) {
				IShellItem *psi;
				HRESULT hr = CreateItemFromObject(_pdtobj, IID_PPV_ARGS(&psi));
				if (SUCCEEDED(hr))
				{
					PWSTR pszName;
					hr = psi->GetDisplayName(SIGDN_NORMALDISPLAY/*SIGDN_FILESYSPATH*/, &pszName);
					if (SUCCEEDED(hr))
					{
						SetDropTip(_pdtobj, _dropImageType, _pszDropTipTemplate ? _pszDropTipTemplate : L"%1", pszName);
						CoTaskMemFree(pszName);
					}
					psi->Release();
				}
				else {
					auto strName = GetDisplayFullNameFromObject(_pdtobj);
					if (!strName.IsEmpty()) {
						SetDropTip(_pdtobj, _dropImageType, _pszDropTipTemplate ? _pszDropTipTemplate : L"%1", strName);
					}
				}
			}
		}
	}
开发者ID:halx99,项目名称:OleDataDemo,代码行数:27,代码来源:PropertiesWnd.cpp

示例12: getOpenDirectory

bool getOpenDirectory(char* out, int max_size, const char* starting_dir)
{
	bool ret = false;
	IFileDialog* pfd;
	if (SUCCEEDED(CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd))))
	{
		if (starting_dir)
		{
			PIDLIST_ABSOLUTE pidl;
			WCHAR wstarting_dir[MAX_PATH];
			WCHAR* wc = wstarting_dir;
			for (const char *c = starting_dir; *c && wc - wstarting_dir < MAX_PATH - 1; ++c, ++wc)
			{
				*wc = *c == '/' ? '\\' : *c;
			}
			*wc = 0;

			HRESULT hresult = ::SHParseDisplayName(wstarting_dir, 0, &pidl, SFGAO_FOLDER, 0);
			if (SUCCEEDED(hresult))
			{
				IShellItem* psi;
				hresult = ::SHCreateShellItem(NULL, NULL, pidl, &psi);
				if (SUCCEEDED(hresult))
				{
					pfd->SetFolder(psi);
				}
				ILFree(pidl);
			}
		}

		DWORD dwOptions;
		if (SUCCEEDED(pfd->GetOptions(&dwOptions)))
		{
			pfd->SetOptions(dwOptions | FOS_PICKFOLDERS);
		}
		if (SUCCEEDED(pfd->Show(NULL)))
		{
			IShellItem* psi;
			if (SUCCEEDED(pfd->GetResult(&psi)))
			{
				WCHAR* tmp;
				if (SUCCEEDED(psi->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &tmp)))
				{
					char* c = out;
					while (*tmp && c - out < max_size - 1)
					{
						*c = (char)*tmp;
						++c;
						++tmp;
					}
					*c = '\0';
					ret = true;
				}
				psi->Release();
			}
		}
		pfd->Release();
	}
	return ret;
}
开发者ID:gunsafighter,项目名称:LumixEngine,代码行数:60,代码来源:platform_interface.cpp

示例13: ReportSelectedItems

void ReportSelectedItems(IUnknown *punkSite, IShellItemArray *psia)
{
    DWORD cItems;
    HRESULT hr = psia->GetCount(&cItems);
    for (DWORD i = 0; SUCCEEDED(hr) && (i < cItems); i++)
    {
        IShellItem *psi;
        hr = psia->GetItemAt(i, &psi);
        if (SUCCEEDED(hr))
        {
            PWSTR pszName;
            hr = GetIDListName(psi, &pszName);
            if (SUCCEEDED(hr))
            {
                HWND hwnd;
                IUnknown_GetWindow(punkSite, &hwnd);
                int nButton;
                const TASKDIALOG_COMMON_BUTTON_FLAGS buttonFlags = (i == (cItems - 1)) ? TDCBF_OK_BUTTON : TDCBF_OK_BUTTON | TDCBF_CANCEL_BUTTON;
                WCHAR szMsg[128];
                StringCchPrintf(szMsg, ARRAYSIZE(szMsg), L"Item %d of %d added to basket", i + 1, cItems);
                if (SUCCEEDED(TaskDialog(hwnd, 0, L"Items Addded to Basket", szMsg, pszName, buttonFlags, NULL, &nButton)))
                {
                    hr = (nButton == IDCANCEL) ? HRESULT_FROM_WIN32(ERROR_CANCELLED) : S_OK;
                }
                CoTaskMemFree(pszName);
            }
            psi->Release();
        }
    }
}
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:30,代码来源:CommonFileDialogModes.cpp

示例14: CoCreateInstance

char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd)
{
	IFileDialog *d = NULL;
	FILEOPENDIALOGOPTIONS opts;
	IShellItem *result = NULL;
	WCHAR *wname = NULL;
	char *name = NULL;
	HRESULT hr;

	hr = CoCreateInstance(clsid,
		NULL, CLSCTX_INPROC_SERVER,
		iid, (LPVOID *) (&d));
	if (hr != S_OK) {
		logHRESULT(L"error creating common item dialog", hr);
		// always return NULL on error
		goto out;
	}
	hr = d->GetOptions(&opts);
	if (hr != S_OK) {
		logHRESULT(L"error getting current options", hr);
		goto out;
	}
	opts |= optsadd;
	// the other platforms don't check read-only; we won't either
	opts &= ~FOS_NOREADONLYRETURN;
	hr = d->SetOptions(opts);
	if (hr != S_OK) {
		logHRESULT(L"error setting options", hr);
		goto out;
	}
	hr = d->Show(parent);
	if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))
		// cancelled; return NULL like we have ready
		goto out;
	if (hr != S_OK) {
		logHRESULT(L"error showing dialog", hr);
		goto out;
	}
	hr = d->GetResult(&result);
	if (hr != S_OK) {
		logHRESULT(L"error getting dialog result", hr);
		goto out;
	}
	hr = result->GetDisplayName(SIGDN_FILESYSPATH, &wname);
	if (hr != S_OK) {
		logHRESULT(L"error getting filename", hr);
		goto out;
	}
	name = toUTF8(wname);

out:
	if (wname != NULL)
		CoTaskMemFree(wname);
	if (result != NULL)
		result->Release();
	if (d != NULL)
		d->Release();
	return name;
}
开发者ID:08opt,项目名称:libui,代码行数:59,代码来源:stddialogs.cpp

示例15: 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


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