예제 #1
0
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;
}
예제 #2
0
파일: Core.cpp 프로젝트: mgukowsky/MAGSNES
const bool Core::select_file() {
	//Open file dialog, straight from https://msdn.microsoft.com/en-us/library/windows/desktop/ff485843(v=vs.85).aspx
	HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
	PWSTR pszFilePath = nullptr;

	if (SUCCEEDED(hr)) {
		IFileOpenDialog *pFileOpen;

		// Create the FileOpenDialog object.
		hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
			IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));

		if (SUCCEEDED(hr)) {
			//Boilerplate for only showing *.nes files in the dialog. See the MSDN docs more info.
			COMDLG_FILTERSPEC fileFilter;
			fileFilter.pszName = L"iNES";
			fileFilter.pszSpec = L"*.nes";

			pFileOpen->SetFileTypes(1, &fileFilter);
			pFileOpen->SetFileTypeIndex(1);
			pFileOpen->SetDefaultExtension(L"nes");

			// 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);

					if (SUCCEEDED(hr)) {
						logmsg("Opening file");
					} else {
						pszFilePath = nullptr;
					}
					pItem->Release();
				}
			}
			pFileOpen->Release();
		}
		CoUninitialize();
	}

	if (pszFilePath == nullptr) {
		alert_error("Unable to open file! File must have the extension \".nes\"");
		return false;
	}

	//Convert wchar_t string to char string
	std::size_t i;
	wcstombs_s(&i, fileSelection, pszFilePath, MAX_PATH);

	return true;
}
예제 #3
0
//  Open an audio/video file.
void OnFileOpen(HWND hwnd)
{
    IFileOpenDialog *pFileOpen = NULL;
    IShellItem *pItem = NULL;
    PWSTR pszFilePath = NULL;

    // Create the FileOpenDialog object.
    HRESULT hr = CoCreateInstance(__uuidof(FileOpenDialog), NULL, 
        CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileOpen));
    if (FAILED(hr))
    {
        goto done;
    }

    // Show the Open dialog box.
    hr = pFileOpen->Show(NULL);
    if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))
    {
        // The user canceled the dialog. Do not treat as an error.
        hr = S_OK;
        goto done;
    }
    else if (FAILED(hr))
    {
        goto done;
    }

    // Get the file name from the dialog box.
    hr = pFileOpen->GetResult(&pItem);
    if (FAILED(hr))
    {
        goto done;
    }

    hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
    if (FAILED(hr))
    {
        goto done;
    }

    // Display the file name to the user.
    hr = g_pPlayer->OpenURL(pszFilePath);
    if (SUCCEEDED(hr))
    {
        UpdateUI(hwnd, OpenPending);
    }

done:
    if (FAILED(hr))
    {
        NotifyError(hwnd, L"Could not open the file.", hr);
        UpdateUI(hwnd, Closed);
    }
    CoTaskMemFree(pszFilePath);
    SafeRelease(&pItem);
    SafeRelease(&pFileOpen);
}
예제 #4
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;
}
예제 #5
0
파일: FileOpen.cpp 프로젝트: lucaszardo/SCV
void FileOpen::showDialog()
{
#ifdef _WIN32
   path = NULL;

   HRESULT hResult = CoInitializeEx(NULL,
      COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

   if (SUCCEEDED(hResult))
   {
      //Create a instance to open the fileOpenDialog

      IFileOpenDialog *pFileOpen;

      hResult = CoCreateInstance(CLSID_FileOpenDialog, NULL,
         CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileOpen));

      if (SUCCEEDED(hResult))
      {
         //show the File Open
         hResult = pFileOpen->Show(NULL);

         //get the file name result
         if (SUCCEEDED(hResult))
         {
            IShellItem *pItem;
            hResult = pFileOpen->GetResult(&pItem);
            if (SUCCEEDED(hResult))
            {
               PWSTR FilePath;
               hResult = pItem->GetDisplayName(SIGDN_FILESYSPATH, &FilePath);

               //get the file name and copy to "path"
               if (SUCCEEDED(hResult))
               {
                  int count = wcslen(FilePath);
                  path = new char[2*count];
                  wcstombs(path, FilePath, count);
                  path[count] = '\0';
                  CoTaskMemFree(FilePath);

               }
               pItem->Release();
            }
         }
         pFileOpen->Release();
      }
      CoUninitialize();
   }
#else
   std::cout << "Sorry, this is not implemented on linux yet =(" << std::endl;
   return;
#endif
}
예제 #6
0
파일: Anthony.cpp 프로젝트: elepro/Anthony
BOOL ReadFromFile()
{
	IFileOpenDialog *pDlg;
	COMDLG_FILTERSPEC FileTypes[] = {
		{ L"PS2 MemoryCard files", L"*.ps2" },
		{ L"All files", L"*.*" }
	};

	HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDlg));
	WCHAR cPath[MAX_PATH] = L"";
	GetCurrentDirectoryW(sizeof(cPath) / sizeof(cPath[0]), cPath);
	IShellItem *psiFolder, *psiParent;
	SHCreateItemFromParsingName(cPath, NULL, IID_PPV_ARGS(&psiFolder));
	psiFolder->GetParent(&psiParent);

	//初期フォルダの指定
	pDlg->SetFolder(psiFolder);
	//フィルターの指定
	pDlg->SetFileTypes(_countof(FileTypes), FileTypes);
	//ダイアログ表示
	hr = pDlg->Show(NULL);

	//ファイル名
	LPOLESTR pwsz = NULL;
	if (SUCCEEDED(hr))
	{
		IShellItem *pItem;
		hr = pDlg->GetResult(&pItem);
		if (SUCCEEDED(hr))
		{

			hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pwsz);
			if (SUCCEEDED(hr))
			{
				HANDLE hFile;
				hFile = CreateFile(pwsz, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
				if (hFile)
				{
					DWORD BytesRead;
					BOOL b = ReadFile(hFile, &(byteMemDat.Byte), sizeof(byteMemDat), &BytesRead, NULL);
					if (BytesRead)
					{
						CloseHandle(hFile);
					}
				}
			}
		}
	}
	UpdateDataList(&byteMemDat);
	return TRUE;
}
예제 #7
0
void EditorScreen::LoadMap()
{
	HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | 
        COINIT_DISABLE_OLE1DDE);
	
    if (SUCCEEDED(hr))
    {
		IFileOpenDialog *pFileOpen = NULL;

		HRESULT hr = CoCreateInstance(__uuidof(FileOpenDialog), NULL, 
        CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileOpen));

		if (SUCCEEDED(hr))
		{
			hr = pFileOpen->SetDefaultExtension(L"xml");
			hr = pFileOpen->SetFileTypes(ARRAYSIZE(c_rgSaveTypes), c_rgSaveTypes);
			hr = pFileOpen->Show(NULL);

			if (SUCCEEDED(hr))
			{
				IShellItem *pItem;
				hr = pFileOpen->GetResult(&pItem);

				if (SUCCEEDED(hr))
				{
					PWSTR pszFilePath;
					hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);

					// Display the file name to the user.
					if (SUCCEEDED(hr))
					{
						// Reset current Map information
						ResetMap();

						std::string filePath = utf8_encode(pszFilePath);
						map->LoadMap(filePath);

						CoTaskMemFree(pszFilePath);
					}
					pItem->Release();
				}
			}
			pFileOpen->Release();
		}
		CoUninitialize();
	}
}
예제 #8
0
파일: Game.cpp 프로젝트: and0p/NesVoxel
string getFilePathWithDialog()
{
	string path = "";
	HRESULT hr = CoInitializeEx(NULL, COINITBASE_MULTITHREADED |
		COINIT_DISABLE_OLE1DDE);
	if (SUCCEEDED(hr))
	{
		IFileOpenDialog *pFileOpen;

		// Create the FileOpenDialog object.
		hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
			IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));

		if (SUCCEEDED(hr))
		{
			// 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))
				{
					PWSTR pszFilePath;
					hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
					// Display the file name to the user.
					if (SUCCEEDED(hr))
					{
						//MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
						char buffer[500];
						wcstombs(buffer, pszFilePath, 500);
						path = buffer;
						CoTaskMemFree(pszFilePath);
					}
					pItem->Release();
				}
			}
			pFileOpen->Release();
		}
		CoUninitialize();
	}
	return path;
}
예제 #9
0
PWSTR openUserFileDiaglog()
{
	PWSTR pszFilePath = NULL;

	HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
	if (SUCCEEDED(hr))
	{
		IFileOpenDialog *pFileOpen = NULL;

		// Create the FileOpenDialog object.
		hr = CoCreateInstance(
			CLSID_FileOpenDialog,
			NULL,
			CLSCTX_ALL,
			IID_IFileOpenDialog,
			(void**)&pFileOpen);

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

			// Get the file name from the dialog box.
			if (SUCCEEDED(hr))
			{
				IShellItem *pItem = NULL;

				hr = pFileOpen->GetResult(&pItem);
				if (SUCCEEDED(hr))
				{
					hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
					pItem->Release();
				}
			}

			pFileOpen->Release();
		}

		CoUninitialize();
	}

	return pszFilePath;
}
예제 #10
0
파일: lxcwin.cpp 프로젝트: tfg13/LanXchange
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;
}
예제 #11
0
int openFileGetName2()
{
	HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);

	if (SUCCEEDED(hr))
	{
		IFileOpenDialog *pFileOpen;
		// Create the FileOpenDialog object.
		hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
			IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
		if (SUCCEEDED(hr))
		{
			// 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, &endnFile);

					// Display the file name to the user.
					if (SUCCEEDED(hr))
					{
						endnFILE = endnFile;
						CoTaskMemFree(endnFile);
					}
					pItem->Release();
				}
			}
			pFileOpen->Release();
		}
		CoUninitialize();
	}

	return 0;
}
예제 #12
0
void gameOfLife3D::MainWnd::OnOpenFile()
{
    static COMDLG_FILTERSPEC dialogFiltersMM[] = {
        { L"Life File(*.lif;*.life)", L"*.lif;*.life" },
        { L"All types(*.*)", L"*.*" },
    };

    IFileOpenDialog *pFileOpenDialog = nullptr;

    HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
                                  nullptr,
                                  CLSCTX_INPROC_SERVER,
                                  IID_PPV_ARGS(&pFileOpenDialog));

    if (SUCCEEDED(hr)) {
        hr = pFileOpenDialog->SetFileTypes(2, dialogFiltersMM);
    }
    IShellItem *pResult = nullptr;
    if (SUCCEEDED(hr)) {
        hr = pFileOpenDialog->Show(m_hwnd);
    }
    if (SUCCEEDED(hr)) {
        hr = pFileOpenDialog->GetResult(&pResult);
    }
    WCHAR *pPath = nullptr;
    if (SUCCEEDED(hr)) {
        hr = pResult->GetDisplayName(SIGDN_FILESYSPATH, &pPath);
    }
    if (SUCCEEDED(hr)) {
        std::wstring fileName(pPath);
        auto lifeFile = std::make_shared<gameOfLife3D::io::LifeFile>();
        lifeFile->Load(fileName);
        m_canvasPanel->SetLifeFile(lifeFile);
    }
    if (pPath != nullptr) {
        CoTaskMemFree(pPath);
    }
    SafeRelease(&pResult);
    SafeRelease(&pFileOpenDialog);
}
예제 #13
0
/* 
* OpenFileName
* Opens a folder dialog box, and returns the path
* Returns an empty string if dialog is canceled
*/
std::string OpenFolder(/*char *filter,*/ HWND owner) {
	HRESULT hr;
	IFileOpenDialog *pOpenFolderDialog;
	std::string folderPath;

	// CoCreate the dialog object.
	hr = CoCreateInstance(CLSID_FileOpenDialog, 
		NULL, 
		CLSCTX_INPROC_SERVER,
		IID_PPV_ARGS(&pOpenFolderDialog));

	if (SUCCEEDED(hr))
	{
		pOpenFolderDialog->SetOptions(FOS_PICKFOLDERS);

		// Show the dialog
		hr = pOpenFolderDialog->Show(owner);

		if (SUCCEEDED(hr))
		{
			// Obtain the result of the user's interaction with the dialog.
			IShellItem *psiResult;
			hr = pOpenFolderDialog->GetResult(&psiResult);

			LPWSTR folderW = NULL;
			psiResult->GetDisplayName(SIGDN_FILESYSPATH, &folderW);
			char* folderC;
			folderC = new char[300];
			folderPath = wcstombs(folderC,folderW, 300);
			folderPath = folderC;

			//free memory
			if (folderC) delete[] folderC;
			CoTaskMemFree ( folderW );
			psiResult->Release();
		}
	}
	pOpenFolderDialog->Release();
	return folderPath;
}
예제 #14
0
std::string Dlg_MemBookmark::ImportDialog()
{
	std::string str;

	if ( g_pCurrentGameData->GetGameID() == 0 )
	{
		MessageBox( nullptr, _T("ROM not loaded: please load a ROM first!"), _T("Error!"), MB_OK );
		return str;
	}

	IFileOpenDialog* pDlg = nullptr;
	HRESULT hr = CoCreateInstance( CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>( &pDlg ) );
	if ( hr == S_OK )
	{
		hr = pDlg->SetFileTypes( ARRAYSIZE( c_rgFileTypes ), c_rgFileTypes );
		if ( hr == S_OK )
		{
			hr = pDlg->Show( nullptr );
			if ( hr == S_OK )
			{
				IShellItem* pItem = nullptr;
				hr = pDlg->GetResult( &pItem );
				if ( hr == S_OK )
				{
					LPWSTR pStr = nullptr;
					hr = pItem->GetDisplayName( SIGDN_FILESYSPATH, &pStr );
					if ( hr == S_OK )
					{
						str = Narrow( pStr );
					}

					pItem->Release();
				}
			}
		}
		pDlg->Release();
	}

	return str;
}
예제 #15
0
void gameOfLife3D::MainWnd::OnOpenCSFile()
{
    static COMDLG_FILTERSPEC dialogFiltersMM[] = {
        { L"effect File(*.fx)", L"*.fx" },
        { L"compute shader File(*.cs)", L"*.cs" },
        { L"All types(*.*)", L"*.*" },
    };

    IFileOpenDialog *pFileOpenDialog = nullptr;

    HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
                                  nullptr,
                                  CLSCTX_INPROC_SERVER,
                                  IID_PPV_ARGS(&pFileOpenDialog));

    if (SUCCEEDED(hr)) {
        hr = pFileOpenDialog->SetFileTypes(3, dialogFiltersMM);
    }
    IShellItem *pResult = nullptr;
    if (SUCCEEDED(hr)) {
        hr = pFileOpenDialog->Show(m_hwnd);
    }
    if (SUCCEEDED(hr)) {
        hr = pFileOpenDialog->GetResult(&pResult);
    }
    WCHAR *pPath = nullptr;
    if (SUCCEEDED(hr)) {
        hr = pResult->GetDisplayName(SIGDN_FILESYSPATH, &pPath);
    }
    if (SUCCEEDED(hr)) {
        std::wstring fileName(pPath);
        m_canvasPanel->OpenCSFile(fileName);
    }
    if (pPath != nullptr) {
        CoTaskMemFree(pPath);
    }
    SafeRelease(&pResult);
    SafeRelease(&pFileOpenDialog);
}
bool PromptFileLocation(std::wstring& resultPath, std::wstring title=L"Open", fileType filterType=ft_exe)
{
    HRESULT hr;
    
    hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    if (!SUCCEEDED(hr))
    {
        CoUninitialize();
        return false;
    }

    IFileOpenDialog *pFileOpen;
    // Create the FileOpenDialog object.
    hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
    if (!SUCCEEDED(hr))
    {
        pFileOpen->Release();
        CoUninitialize();
        return false;
    }

    // Set the filter type
    switch (filterType)
    {
    case ft_exe:
            {
                COMDLG_FILTERSPEC filter;
                filter.pszName = L"Windows Executable";
                filter.pszSpec = L"*.exe";
                hr = pFileOpen->SetFileTypes(1, &filter);
                break;
            }
    default:
        {
            break;
        }
    }
    if (!SUCCEEDED(hr))
    {
        pFileOpen->Release();
        CoUninitialize();
        return false;
    }

    // Set the title
    hr = pFileOpen->SetTitle(L"Please locate your Blender executable.");
    if (!SUCCEEDED(hr))
    {
        pFileOpen->Release();
        CoUninitialize();
        return false;
    }

    // Show the Open dialog box.
    hr = pFileOpen->Show(NULL);
    if (!SUCCEEDED(hr))
    {
        pFileOpen->Release();
        CoUninitialize();
        return false;
    }

    // Get the file name from the open dialog box.
    IShellItem *pItem;
    hr = pFileOpen->GetResult(&pItem);
    if (!SUCCEEDED(hr))
    {
        pItem->Release();
        pFileOpen->Release();
        CoUninitialize();
        return false;
    }

    PWSTR pszFilePath;
    hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);

    if (!SUCCEEDED(hr))
    {
        pItem->Release();
        pFileOpen->Release();
        CoUninitialize();
        CoTaskMemFree(pszFilePath);
        return false;
    }

    resultPath = pszFilePath;
    CoTaskMemFree(pszFilePath);
    pItem->Release();
    pFileOpen->Release();
    CoUninitialize();
    return true;
}
예제 #17
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;
}
예제 #18
0
void KPR_system_openDirectory(xsMachine* the)
{
	HRESULT hr;
	xsIntegerValue argc = xsToInteger(xsArgc);
	IFileOpenDialog *pFileOpen = NULL;
	IShellItem *pItem = NULL;
	xsStringValue string;
	PWSTR wideString = NULL;
	xsIntegerValue urlLength;
	xsStringValue url = NULL;
	hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, (LPVOID *)&pFileOpen);
	if (!SUCCEEDED(hr)) goto bail;
	if ((argc > 0) && xsTest(xsArg(0))) {
		if (xsFindString(xsArg(0), xsID_prompt, &string)) {
			wideString = xsStringToWideString(string);
			hr = pFileOpen->SetTitle(wideString);
			if (!SUCCEEDED(hr)) goto bail;
			CoTaskMemFree(wideString);
			wideString = NULL;
		}
		if (xsFindString(xsArg(0), xsID_message, &string)) {
			wideString = xsStringToWideString(string);
			hr = pFileOpen->SetTitle(wideString);
			if (!SUCCEEDED(hr)) goto bail;
			CoTaskMemFree(wideString);
			wideString = NULL;
		}
		if (xsFindString(xsArg(0), xsID_url, &string)) {
			wideString = xsStringToWideString(string);
			hr = SHCreateItemFromParsingName(wideString, NULL, IID_IShellItem, (LPVOID *)&pItem);
			if (!SUCCEEDED(hr)) goto bail;
			CoTaskMemFree(wideString);
			wideString = NULL;
			hr = pFileOpen->SetFolder(pItem);
			if (!SUCCEEDED(hr)) goto bail;
			pItem->Release();
			pItem = NULL;
		}
	}
	hr = pFileOpen->SetOptions(FOS_PICKFOLDERS);
	if (!SUCCEEDED(hr)) goto bail;
	hr = pFileOpen->Show(GetForegroundWindow());
	if (!SUCCEEDED(hr)) goto bail;
	hr = pFileOpen->GetResult(&pItem);
	if (!SUCCEEDED(hr)) goto bail;
	hr = pItem->GetDisplayName(SIGDN_URL, &wideString);
	if (!SUCCEEDED(hr)) goto bail;
	
	urlLength = WideCharToMultiByte(CP_UTF8, 0, wideString, -1, NULL, 0, NULL, NULL);
	FskMemPtrNew(urlLength + 1, &url);
	WideCharToMultiByte(CP_UTF8, 0, wideString, -1, url, urlLength, NULL, NULL);
	url[urlLength - 1] = '/';
	url[urlLength] = 0;
	(void)xsCallFunction1(xsArg(1), xsNull, xsString(url));
	
bail:
	FskMemPtrDispose(url);
	if (wideString)
		CoTaskMemFree(wideString);
	if (pItem)
		pItem->Release();
	if (pFileOpen)
		pFileOpen->Release();
}
예제 #19
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;
}
예제 #20
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;
	}
예제 #21
0
static INT_PTR CALLBACK DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    DWORD id;
    //	NMHDR *p;


    switch (uMsg)
    {
    case WM_COMMAND:
        id = LOWORD(wParam);
        if (id == IDOK || id == IDCANCEL)
        {
            if (id == IDOK)
            {
                PC_SetPluginVar(m_dwPluginID, VAR_TEXT_COLOR, dwTextColor);
                PC_SetPluginVar(m_dwPluginID, VAR_BACKGROUND_COLOR, dwBackgroundColor);
                PC_SetPluginVar(m_dwPluginID, VAR_TEXT_FILE, szFileName.c_str());
                PC_SetPluginVar(m_dwPluginID, VAR_TEXT_FONT_FAMILY, szFontFamily.c_str());
                PC_SetPluginVar(m_dwPluginID, VAR_TEXT_FILE, szFileName.c_str());
                PC_SetPluginVar(m_dwPluginID, VAR_TEXT_FONT_SIZE, dwFontSize);
                PC_SetPluginVar(m_dwPluginID, VAR_SHOW_BACKGROUND, Button_GetCheck(GetDlgItem(hwnd, IDC_SHOW_BACKGROUND)) == BST_CHECKED);
                int style = (bBold ? 1 : 0) | (bItalic ? 2 : 0);
                PC_SetPluginVar(m_dwPluginID, VAR_TEXT_FONT_STYLE, style);
            }

            EndDialog(hwnd, id);
        }

        if (id == IDC_TEXT_COLOR_BTN || id == IDC_BACKGROUND_COLOR_BTN)
        {
            DWORD &color_var = (id == IDC_TEXT_COLOR_BTN) ? dwTextColor : dwBackgroundColor;
            COLORREF custColors[16];
            CHOOSECOLOR cc = { 0 };
            cc.lStructSize = sizeof(cc);
            cc.hwndOwner = hwnd;
            cc.rgbResult = color_var;
            cc.Flags = CC_FULLOPEN | CC_RGBINIT;
            cc.lpCustColors = custColors;
            if (ChooseColor(&cc))
            {
                color_var = cc.rgbResult;
                InvalidateRect(hwnd, 0, 0);
            }
        }

        if (id == IDC_TEXT_FONT)
        {
            LOGFONT lf = { 0 };
            lf.lfItalic = bItalic;
            wcscpy_s(lf.lfFaceName, szFontFamily.c_str());
            HDC dc = GetDC(hwnd);
            lf.lfHeight = -MulDiv(dwFontSize, GetDeviceCaps(dc, LOGPIXELSY), 72);
            lf.lfWeight = 400;

            CHOOSEFONT cf = { 0 };
            cf.lStructSize = sizeof(cf);
            cf.hwndOwner = hwnd;
            cf.lpLogFont = &lf;
            cf.iPointSize = dwFontSize * 10;
            cf.Flags = CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT | CF_NOSCRIPTSEL;
            if (ChooseFont(&cf))
            {
                bItalic = lf.lfItalic != 0;
                bBold = lf.lfWeight > 500;
                szFontFamily = lf.lfFaceName;
                dwFontSize = (-lf.lfHeight * 72) / GetDeviceCaps(dc, LOGPIXELSY);
                SetFontButtonText(hwnd);
            }
            ReleaseDC(hwnd, dc);

        }
        if (id == IDC_TEXT_FILE) {
            HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
                                        COINIT_DISABLE_OLE1DDE);
            if (SUCCEEDED(hr))
            {
                IFileOpenDialog *pFileOpen;
                COMDLG_FILTERSPEC rgSpec[] =
                {
                    { L"Text Files", L"*.txt" },
                    { L"All Files", L"*.*" },
                };
                // Create the FileOpenDialog object.
                hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
                                      IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));

                if (SUCCEEDED(hr))
                {
                    // Show the Open dialog box.
                    pFileOpen->SetFileTypes(2, rgSpec);

                    hr = pFileOpen->Show(NULL);

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

                            // Display the file name to the user.
                            if (SUCCEEDED(hr))
                            {
                                //MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
                                //szFileName = L"CATS";
                                szFileName = pszFilePath;
                                SetFileNameButtonText(hwnd);
                                CoTaskMemFree(pszFilePath);
                            }
                            pItem->Release();
                        }
                    }
                    pFileOpen->Release();
                }
                CoUninitialize();
            }

        }

        break;

    case WM_NOTIFY:
        break;

    case WM_DRAWITEM:
    {
        auto lpDIS = (LPDRAWITEMSTRUCT)lParam;
        if (lpDIS->CtlID == IDC_TEXT_COLOR_BTN)
            DrawColorButton(lpDIS, dwTextColor);
        if (lpDIS->CtlID == IDC_BACKGROUND_COLOR_BTN)
            DrawColorButton(lpDIS, dwBackgroundColor);
        break;
    }


    case WM_INITDIALOG:
        InitSettingsDialog(hwnd);
        return true;
    }

    return false;
}
예제 #22
-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;
}