Esempio n. 1
0
// @pymethod <o PyIShellItem>|PyIShellItem|GetParent|Retrieves the parent of this item
PyObject *PyIShellItem::GetParent(PyObject *self, PyObject *args)
{
	IShellItem *pISI = GetI(self);
	if ( pISI == NULL )
		return NULL;
	IShellItem *psi;
	if ( !PyArg_ParseTuple(args, ":GetParent") )
		return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pISI->GetParent( &psi );

	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pISI, IID_IShellItem );
	return PyCom_PyObjectFromIUnknown(psi, IID_IShellItem, FALSE);
}
Esempio n. 2
0
	bool BrowseFolderDialog(HWND hwndOwner,TSTask::String *pDirectory,LPCTSTR pszTitle)
	{
		if (pDirectory==nullptr)
			return false;

		IFileOpenDialog *pFileOpenDialog;
		HRESULT hr;

		hr=::CoCreateInstance(CLSID_FileOpenDialog,nullptr,CLSCTX_INPROC_SERVER,
							  IID_PPV_ARGS(&pFileOpenDialog));
		if (FAILED(hr))
			return false;

		FILEOPENDIALOGOPTIONS Options;
		pFileOpenDialog->GetOptions(&Options);
		pFileOpenDialog->SetOptions(Options | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM);

		if (!pDirectory->empty()) {
			IShellItem *psiFolder;
			hr=::SHCreateItemFromParsingName(pDirectory->c_str(),nullptr,IID_PPV_ARGS(&psiFolder));
			if (SUCCEEDED(hr)) {
				IShellItem *psiParent;
				hr=psiFolder->GetParent(&psiParent);
				if (SUCCEEDED(hr)) {
					pFileOpenDialog->SetFolder(psiParent);
					LPWSTR pszName;
					hr=psiFolder->GetDisplayName(SIGDN_NORMALDISPLAY,&pszName);
					if (SUCCEEDED(hr)) {
						pFileOpenDialog->SetFileName(pszName);
						::CoTaskMemFree(pszName);
					}
					psiParent->Release();
				}
				psiFolder->Release();
			}
		}

		if (!TSTask::IsStringEmpty(pszTitle))
			pFileOpenDialog->SetTitle(pszTitle);

		bool fOK=false;
		hr=pFileOpenDialog->Show(hwndOwner);
		if (SUCCEEDED(hr)) {
			LPWSTR pszPath;
			IShellItem *psi;
			hr=pFileOpenDialog->GetResult(&psi);
			if (SUCCEEDED(hr)) {
				hr=psi->GetDisplayName(SIGDN_FILESYSPATH,&pszPath);
				if (SUCCEEDED(hr)) {
					*pDirectory=pszPath;
					fOK=true;
					::CoTaskMemFree(pszPath);
				}
				psi->Release();
			}
		}

		pFileOpenDialog->Release();

		return fOK;
	}