Exemplo n.º 1
1
BOOL OpenFilesVistaUp(HWND hwnd, lFILEINFO *pFInfoList)
{
    IFileOpenDialog *pfd;
	IFileDialogCustomize *pfdc;
	FILEOPENDIALOGOPTIONS dwOptions;
	DWORD dwCookie = 0;
    
	CoInitialize(NULL);
    
    // CoCreate the dialog object.
    HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, 
                                  NULL, 
                                  CLSCTX_INPROC_SERVER, 
                                  IID_PPV_ARGS(&pfd));

    if (SUCCEEDED(hr)) {

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

		if(SUCCEEDED(hr)) {

			hr = pfdc->EnableOpenDropDown(FDIALOG_OPENCHOICES);
			if (SUCCEEDED(hr))
			{
				hr = pfdc->AddControlItem(FDIALOG_OPENCHOICES, FDIALOG_CHOICE_OPEN, L"&Open");
				if (SUCCEEDED(hr))
				{
					hr = pfdc->AddControlItem(FDIALOG_OPENCHOICES, 
											  FDIALOG_CHOICE_REPARENT, 
											  L"&Reparent hash file");
                    hr = pfdc->AddControlItem(FDIALOG_OPENCHOICES, 
											  FDIALOG_CHOICE_ALLHASHES, 
											  L"&Open all hash files");
                    hr = pfdc->AddControlItem(FDIALOG_OPENCHOICES, 
											  FDIALOG_CHOICE_BSD, 
											  L"&Force open as BSD-style");
				}
			}
		}

		pfdc->Release();

        hr = pfd->GetOptions(&dwOptions);
        
        if (SUCCEEDED(hr)) {
            hr = pfd->SetOptions(dwOptions | FOS_ALLOWMULTISELECT | FOS_FORCEFILESYSTEM);

			if (SUCCEEDED(hr)) {
				COpenFileListener *ofl = new COpenFileListener(pFInfoList);
				hr = pfd->Advise(ofl,&dwCookie);

				if (SUCCEEDED(hr)) {
					hr = pfd->Show(hwnd);

					if (SUCCEEDED(hr)) {
						
					}

					pfd->Unadvise(dwCookie);
				}
			}
        }
		
        pfd->Release();
    }

	CoUninitialize();

    return SUCCEEDED(hr);
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
QString qt_win_CID_get_existing_directory(const QFileDialogArgs &args)
{
    QString result;
    QDialog modal_widget;
    modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true);
    modal_widget.setParent(args.parent, Qt::Window);
    QApplicationPrivate::enterModal(&modal_widget);

    IFileOpenDialog *pfd = 0;
    HRESULT hr = CoCreateInstance(QT_CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
                                  QT_IID_IFileOpenDialog, reinterpret_cast<void**>(&pfd));

    if (SUCCEEDED(hr)) {
        qt_win_set_IFileDialogOptions(pfd, args.selection,
                                      args.directory, args.caption,
                                      QStringList(), QFileDialog::ExistingFile,
                                      args.options);

        // Set the FOS_PICKFOLDERS flag
        DWORD newOptions;
        hr = pfd->GetOptions(&newOptions);
        newOptions |= (FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM);
        if (SUCCEEDED(hr) && SUCCEEDED((hr = pfd->SetOptions(newOptions)))) {
            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 result
                IShellItem *psi = 0;
                hr = pfd->GetResult(&psi);
                if (SUCCEEDED(hr)) {
                    // Retrieve the file name from shell item.
                    wchar_t *pszPath;
                    hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);
                    if (SUCCEEDED(hr)) {
                        result = QString::fromWCharArray(pszPath);
                        CoTaskMemFree(pszPath);
                    }
                    psi->Release(); // Free the current item.
                }
            }
        }
    }
    QApplicationPrivate::leaveModal(&modal_widget);

    qt_win_eatMouseMove();

    if (pfd)
        pfd->Release();
    return result;
}
Exemplo n.º 4
0
extern "C" LXCWIN_API HRESULT fileSaveDialog(HWND hWnd, LPWSTR dialogTitle, LPWSTR *result) {
    *result = NULL;
    HRESULT hr = S_OK;
    CoInitialize(nullptr);
    IFileOpenDialog *pfd = NULL;// yes, *open*, since this dialog selects an existing parent dir, not a new file
    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(dialogTitle);

        // ok button text
        pfd->SetOkButtonLabel(L"Choose target");

        // only choose directories
        DWORD dwOptions;
        hr = pfd->GetOptions(&dwOptions);
        if (SUCCEEDED(hr)) {
            pfd->SetOptions(dwOptions | FOS_PICKFOLDERS);
        }

        // show the save dialog
        hr = pfd->Show(hWnd);
        if (SUCCEEDED(hr)) {
            IShellItem *psiaResult;
            hr = pfd->GetResult(&psiaResult);
            if (SUCCEEDED(hr)) {
                psiaResult->GetDisplayName(SIGDN_FILESYSPATH, &(*result));
                psiaResult->Release();
            }
        }
        pfd->Release();
    }
    return hr;
}
Exemplo n.º 5
0
CBrowseFolder::retVal CBrowseFolder::Show(HWND parent, CString& path, const CString& sDefaultPath /* = CString() */)
{
    retVal ret = OK;		//assume OK
    m_sDefaultPath = sDefaultPath;
    if (m_sDefaultPath.IsEmpty() && !path.IsEmpty()) {
        while (!PathFileExists(path) && !path.IsEmpty()) {
            CString p = path.Left(path.ReverseFind(L'\\'));
            if ((p.GetLength() == 2) && (p[1] == L':')) {
                p += L"\\";
                if (p.Compare(path) == 0)
                    p.Empty();
            }
            if (p.GetLength() < 2)
                p.Empty();
            path = p;
        }
        // if the result path already contains a path, use that as the default path
        m_sDefaultPath = path;
    }

    HRESULT hr;

    // Create a new common open file dialog
    IFileOpenDialog* pfd = NULL;
    hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
    if (SUCCEEDED(hr)) {
        // Set the dialog as a folder picker
        DWORD dwOptions;
        if (SUCCEEDED(hr = pfd->GetOptions(&dwOptions))) {
            hr = pfd->SetOptions(dwOptions | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST);
        }

        // Set a title
        if (SUCCEEDED(hr)) {
            TCHAR * nl = _tcschr(m_title, '\n');
            if (nl)
                *nl = 0;
            pfd->SetTitle(m_title);
        }

        // set the default folder
        if (SUCCEEDED(hr)) {
            typedef HRESULT(WINAPI *SHCIFPN)(PCWSTR pszPath, IBindCtx * pbc, REFIID riid, void ** ppv);

            SHCIFPN pSHCIFPN = hLib.GetProcAddress<SHCIFPN>("SHCreateItemFromParsingName");
            if (pSHCIFPN) {
                IShellItem *psiDefault = 0;
                hr = pSHCIFPN(m_sDefaultPath, NULL, IID_PPV_ARGS(&psiDefault));
                if (SUCCEEDED(hr)) {
                    hr = pfd->SetFolder(psiDefault);
                    psiDefault->Release();
                }
            }

        }

        // Show the open file dialog
        if (SUCCEEDED(hr) && SUCCEEDED(hr = pfd->Show(parent))) {
            // Get the selection from the user
            IShellItem* psiResult = NULL;
            hr = pfd->GetResult(&psiResult);
            if (SUCCEEDED(hr)) {
                PWSTR pszPath = NULL;
                hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);
                if (SUCCEEDED(hr)) {
                    path = pszPath;
                    CoTaskMemFree(pszPath);
                }
                psiResult->Release();
            } else
                ret = CANCEL;
        } else
            ret = CANCEL;

        pfd->Release();
    } else {
        BROWSEINFO browseInfo = {};
        browseInfo.hwndOwner = parent;
        browseInfo.pidlRoot = m_root;
        browseInfo.pszDisplayName = m_displayName;
        browseInfo.lpszTitle = m_title;
        browseInfo.ulFlags = m_style;
        browseInfo.lParam = reinterpret_cast<LPARAM>(this);

        PCIDLIST_ABSOLUTE itemIDList = SHBrowseForFolder(&browseInfo);

        //is the dialog canceled?
        if (!itemIDList)
            ret = CANCEL;

        if (ret != CANCEL) {
            if (!SHGetPathFromIDList(itemIDList, path.GetBuffer(MAX_PATH)))		// MAX_PATH ok. Explorer can't handle paths longer than MAX_PATH.
                ret = NOPATH;

            path.ReleaseBuffer();

            CoTaskMemFree((LPVOID)itemIDList);
        }
    }

    return ret;
}
Exemplo n.º 6
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;
	}
Exemplo n.º 7
0
CBrowseFolder::retVal CBrowseFolder::Show(HWND parent, CString& path, const CString& sDefaultPath /* = CString() */)
{
	retVal ret = OK;		//assume OK
	m_sDefaultPath = sDefaultPath;
	if (m_sDefaultPath.IsEmpty() && !path.IsEmpty())
	{
		// if the result path already contains a path, use that as the default path
		m_sDefaultPath = path;
	}

	HRESULT hr;

	// Create a new common open file dialog
	IFileOpenDialog* pfd = NULL;
	hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
	if (SUCCEEDED(hr))
	{
		// Set the dialog as a folder picker
		DWORD dwOptions;
		if (SUCCEEDED(hr = pfd->GetOptions(&dwOptions)))
		{
			hr = pfd->SetOptions(dwOptions | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST);
		}

		// Set a title
		if (SUCCEEDED(hr))
		{
			TCHAR * nl = _tcschr(m_title, '\n');
			if (nl)
				*nl = 0;
			pfd->SetTitle(m_title);
		}

		// set the default folder
		if (SUCCEEDED(hr))
		{
			typedef HRESULT (WINAPI *SHCIFPN)(PCWSTR pszPath, IBindCtx * pbc, REFIID riid, void ** ppv);

			CAutoLibrary hLib = AtlLoadSystemLibraryUsingFullPath(L"shell32.dll");
			if (hLib)
			{
				SHCIFPN pSHCIFPN = (SHCIFPN)GetProcAddress(hLib, "SHCreateItemFromParsingName");
				if (pSHCIFPN)
				{
					IShellItem *psiDefault = 0;
					hr = pSHCIFPN(m_sDefaultPath, NULL, IID_PPV_ARGS(&psiDefault));
					if (SUCCEEDED(hr))
					{
						hr = pfd->SetFolder(psiDefault);
						psiDefault->Release();
					}
				}
			}
		}

		if (m_CheckText[0] != 0)
		{
			IFileDialogCustomize* pfdCustomize = 0;
			hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdCustomize));
			if (SUCCEEDED(hr))
			{
				pfdCustomize->StartVisualGroup(100, L"");
				pfdCustomize->AddCheckButton(101, m_CheckText, FALSE);
				if (m_CheckText2[0] != 0)
				{
					pfdCustomize->AddCheckButton(102, m_CheckText2, FALSE);
				}
				pfdCustomize->EndVisualGroup();
				pfdCustomize->Release();
			}
		}

		// Show the open file dialog
		if (SUCCEEDED(hr) && SUCCEEDED(hr = pfd->Show(parent)))
		{
			// Get the selection from the user
			IShellItem* psiResult = NULL;
			hr = pfd->GetResult(&psiResult);
			if (SUCCEEDED(hr))
			{
				PWSTR pszPath = NULL;
				hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);
				if (SUCCEEDED(hr))
				{
					path = pszPath;
					CoTaskMemFree(pszPath);
				}
				psiResult->Release();

				IFileDialogCustomize* pfdCustomize = 0;
				hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdCustomize));
				if (SUCCEEDED(hr))
				{
					pfdCustomize->GetCheckButtonState(101, &m_bCheck);
					pfdCustomize->GetCheckButtonState(102, &m_bCheck2);
					pfdCustomize->Release();
				}
			}
			else
				ret = CANCEL;
		}
		else
			ret = CANCEL;

		pfd->Release();
	}
	else
	{
		BROWSEINFO browseInfo		= {};
		browseInfo.hwndOwner		= parent;
		browseInfo.pidlRoot			= m_root;
		browseInfo.pszDisplayName	= m_displayName;
		browseInfo.lpszTitle		= m_title;
		browseInfo.ulFlags			= m_style;
		browseInfo.lParam			= (LPARAM)this;

		if ((_tcslen(m_CheckText) > 0)||(!m_sDefaultPath.IsEmpty()))
		{
			browseInfo.lpfn = BrowseCallBackProc;
		}

		PCIDLIST_ABSOLUTE itemIDList = SHBrowseForFolder(&browseInfo);

		//is the dialog canceled?
		if (!itemIDList)
			ret = CANCEL;

		if (ret != CANCEL)
		{
			if (!SHGetPathFromIDList(itemIDList, path.GetBuffer(MAX_PATH)))		// MAX_PATH ok. Explorer can't handle paths longer than MAX_PATH.
				ret = NOPATH;

			path.ReleaseBuffer();

			CoTaskMemFree((LPVOID)itemIDList);
		}
	}

	return ret;
}
Exemplo n.º 8
-1
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;
}
Exemplo n.º 9
-1
CBrowseFolder::retVal CBrowseFolder::Show(HWND parent, CString& path, const CString& sDefaultPath /* = CString() */)
{
    retVal ret = OK;        //assume OK
    m_sDefaultPath = sDefaultPath;
    if (m_sDefaultPath.IsEmpty() && !path.IsEmpty())
    {
        while (!PathFileExists(path) && !path.IsEmpty())
        {
            CString p = path.Left(path.ReverseFind('\\'));
            if ((p.GetLength() == 2)&&(p[1] == ':'))
            {
                p += L"\\";
                if (p.Compare(path) == 0)
                    p.Empty();
            }
            if (p.GetLength() < 2)
                p.Empty();
            path = p;
        }
        // if the result path already contains a path, use that as the default path
        m_sDefaultPath = path;
    }

    HRESULT hr;

    // Create a new common open file dialog
    IFileOpenDialog* pfd = NULL;
    hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
    if (SUCCEEDED(hr))
    {
        // Set the dialog as a folder picker
        DWORD dwOptions;
        if (SUCCEEDED(hr = pfd->GetOptions(&dwOptions)))
        {
            hr = pfd->SetOptions(dwOptions | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST);
        }

        // Set a title
        if (SUCCEEDED(hr))
        {
            TCHAR * nl = wcschr(m_title, '\n');
            if (nl)
                *nl = 0;
            pfd->SetTitle(m_title);
        }

        // set the default folder
        if (SUCCEEDED(hr))
        {
            IShellItem *psiDefault = 0;
            hr = SHCreateItemFromParsingName(m_sDefaultPath, NULL, IID_PPV_ARGS(&psiDefault));
            if (SUCCEEDED(hr))
            {
                hr = pfd->SetFolder(psiDefault);
                psiDefault->Release();
            }
        }

        if (m_CheckText[0] != 0)
        {
            IFileDialogCustomize* pfdCustomize = 0;
            hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdCustomize));
            if (SUCCEEDED(hr))
            {
                pfdCustomize->StartVisualGroup(100, L"");
                pfdCustomize->AddCheckButton(101, m_CheckText, FALSE);
                if (m_CheckText2[0] != 0)
                {
                    pfdCustomize->AddCheckButton(102, m_CheckText2, FALSE);
                }
                pfdCustomize->EndVisualGroup();
                pfdCustomize->Release();
            }
        }

        // Show the open file dialog
        if (SUCCEEDED(hr) && SUCCEEDED(hr = pfd->Show(parent)))
        {
            // Get the selection from the user
            IShellItem* psiResult = NULL;
            hr = pfd->GetResult(&psiResult);
            if (SUCCEEDED(hr))
            {
                PWSTR pszPath = NULL;
                hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);
                if (SUCCEEDED(hr))
                {
                    path = pszPath;
                    CoTaskMemFree(pszPath);
                }
                psiResult->Release();

                IFileDialogCustomize* pfdCustomize = 0;
                hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdCustomize));
                if (SUCCEEDED(hr))
                {
                    pfdCustomize->GetCheckButtonState(101, &m_bCheck);
                    pfdCustomize->GetCheckButtonState(102, &m_bCheck2);
                    pfdCustomize->Release();
                }
            }
            else
                ret = CANCEL;
        }
        else
            ret = CANCEL;

        pfd->Release();
    }
    else
    {
        BROWSEINFO browseInfo       = {};
        browseInfo.hwndOwner        = parent;
        browseInfo.pidlRoot         = m_root;
        browseInfo.pszDisplayName   = m_displayName;
        browseInfo.lpszTitle        = m_title;
        browseInfo.ulFlags          = m_style;
        browseInfo.lParam           = (LPARAM)this;
        browseInfo.lpfn             = BrowseCallBackProc;

        PCIDLIST_ABSOLUTE itemIDList = SHBrowseForFolder(&browseInfo);

        //is the dialog canceled?
        if (!itemIDList)
            ret = CANCEL;

        if (ret != CANCEL)
        {
            if (!SHGetPathFromIDList(itemIDList, path.GetBuffer(MAX_PATH)))     // MAX_PATH ok. Explorer can't handle paths longer than MAX_PATH.
                ret = NOPATH;

            path.ReleaseBuffer();

            CoTaskMemFree((LPVOID)itemIDList);
        }
    }

    return ret;
}