예제 #1
1
void BrowseFolderMenuItem::onSelect()
{
	if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
	{
		DropDownMenu* dropDownMenu = dynamic_cast<DropDownMenu*>(getParent());
		if (dropDownMenu)
		{
			BROWSEINFO browseInfo;
			ZeroMemory(&browseInfo, sizeof(browseInfo));
			browseInfo.hwndOwner = winOS->GetWindowsHandle();
			browseInfo.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS;
			PIDLIST_ABSOLUTE pidl = SHBrowseForFolder(&browseInfo);
			if (pidl)
			{	
				if (winOS->GetLibraryManager())
				{
					QSharedPointer<Library> library = winOS->GetLibraryManager()->addFolderAsLibrary(pidl);
					if (library)
					{
						LOG(QString("Library Directory: %1\n").arg(library->getFolderPaths().front()));
						
						// Save the newly created library
						QList<QString> otherLibs = winOS->GetLibraryManager()->getFolderLibraryDirectories();
						GLOBAL(settings).otherLibraries = otherLibs;
						winOS->SaveSettingsFile();
						
						LibraryMenuItem* item = new LibraryMenuItem(library);
						dropDownMenu->select(item);
						SwitchToLibrary(library);
					}
				}
				CoTaskMemFree(pidl);
			}
			else
			{
				// Reselect the last selected object, since this selection failed
				dropDownMenu->select(dropDownMenu->items().front());
			}
		}
		CoUninitialize();
	}
}
예제 #2
1
void CXMLDialog::GetPath(CString& strPath, CString strTitle)
{
	LPITEMIDLIST lpItemList = NULL;
	LPSHELLFOLDER pDesktopFolder;
	if (!strPath.IsEmpty())
	{
		OLECHAR chOlePath[255];
		ULONG   pchEaten;
		ULONG   dwAttributes;

		HRESULT hr = SHGetDesktopFolder(&pDesktopFolder);
		MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, strPath.GetBuffer(MAX_PATH), -1,
	                         chOlePath, MAX_PATH);
		strPath.ReleaseBuffer (-1);

		hr = pDesktopFolder->ParseDisplayName(NULL,
                                            NULL,
                                            chOlePath,
                                            &pchEaten,
                                            &lpItemList,
                                            &dwAttributes);
	}

	BROWSEINFO binfo;
	binfo.hwndOwner = NULL;
	binfo.pidlRoot = lpItemList; //NULL;
	binfo.pszDisplayName = NULL;
	binfo.lpszTitle = (LPCTSTR)strTitle;
	binfo.ulFlags = BIF_RETURNONLYFSDIRS|BIF_RETURNFSANCESTORS|BIF_NONEWFOLDERBUTTON;
	binfo.lpfn = NULL;
	binfo.lParam = 0;
	binfo.iImage = 0;

	LPITEMIDLIST pItemID = SHBrowseForFolder(&binfo);	
	if (!pItemID)
		return;

	TCHAR szPath[MAX_PATH];
	*szPath = _T('\0');
	SHGetPathFromIDList(pItemID, szPath);
	strPath = szPath;
}
예제 #3
0
// private
void ILaunchDialog::choose_client_dir()
{
	char path[MAX_PATH + 1];
	BROWSEINFO bi;

	bi.hwndOwner = m_hwnd;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = path;	// This is just for display: not useful
	bi.lpszTitle = "Choose Client Directory";
	bi.ulFlags = BIF_RETURNONLYFSDIRS;
	bi.lpfn = NULL;
	bi.lParam = 0;
	LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
	if(pidl != NULL && SHGetPathFromIDList(pidl, path))
	{
		m_config.set_client_dir(path);
		SetDlgItemText(m_hwnd, ID_ST_CLIENTDIR, path);
	}
}
예제 #4
0
BOOL fileSelectPath(HWND HWindow,PSTR szTitle,PSTR szPath)
{
  BOOL         retCode;
  LPMALLOC	   pMalloc;
  BROWSEINFO   nBI;
  LPITEMIDLIST pidl;
  
  memset(&nBI,0,sizeof(nBI));
  nBI.hwndOwner      = HWindow;
  nBI.pszDisplayName = szPath;
  nBI.lpszTitle      = szTitle;
  nBI.ulFlags        = BIF_RETURNONLYFSDIRS | BIF_BROWSEFORCOMPUTER;
  if (NULL == (pidl=SHBrowseForFolder(&nBI))) return FALSE;
  retCode = SHGetPathFromIDList(pidl,szPath);
  SHGetMalloc(&pMalloc);
  pMalloc->lpVtbl->Free(pMalloc,pidl);
  pMalloc->lpVtbl->Release(pMalloc);
  return retCode;
}
예제 #5
0
파일: djvuDlg.cpp 프로젝트: mar80nik/djvu
void CDjvuDlg::OnButton2() 
{
	BROWSEINFO bi= {m_hWnd, NULL, NULL, "Please, choose the folder...",
					BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_EDITBOX | BIF_BROWSEFORCOMPUTER,
					NULL, NULL, 0};
		
	LPCITEMIDLIST lpItemDList;
	if(!(lpItemDList=SHBrowseForFolder(&bi)))
	{
	}
	else
	{
		char buff[200];
		SHGetPathFromIDList(lpItemDList, buff); // 
		OutputDir=buff; UpdateData(DlgSet);
	}	
	
	
}
예제 #6
0
파일: Util.cpp 프로젝트: iloveghq/GaborPC
/*****************************************************************
** 函数名:GetPath
** 输 入: 无
** 输 出: CString strPath
**        strPath非空, 表示用户选择的文件夹路径
**        strPath为空, 表示用户点击了“取消”键,取消选择
** 功能描述:显示“选择文件夹”对话框,让用户选择文件夹 结果:如:"E:\xxx个人文件夹\plc"
****************************************************************/
CString CUtil::getPath(HWND hwndOwner)
{
	CString strPath =_T("");
	BROWSEINFO bInfo;
	ZeroMemory(&bInfo, sizeof(bInfo));
	bInfo.hwndOwner = hwndOwner;
	bInfo.lpszTitle = _T("请选择路径: ");
	bInfo.ulFlags = BIF_RETURNONLYFSDIRS;    

	LPITEMIDLIST lpDlist; //用来保存返回信息的IDList
	lpDlist = SHBrowseForFolder(&bInfo) ; //显示选择对话框
	if(lpDlist != NULL)  //用户按了确定按钮
	{
		TCHAR chPath[255]; //用来存储路径的字符串
		SHGetPathFromIDList(lpDlist, chPath);//把项目标识列表转化成字符串
		strPath = chPath; //将TCHAR类型的字符串转换为CString类型的字符串
	}
	return strPath;
}
예제 #7
0
void CCopyDlg::OnBrowse() 
{
    TCHAR folder[MAX_PATH];
    BROWSEINFO bi;
    bi.hwndOwner = m_hWnd;
    bi.pidlRoot = NULL;
    bi.pszDisplayName = folder;
    bi.lpszTitle = _T("Select folder to install into");
    bi.ulFlags = 0;
    bi.lpfn = NULL;
    bi.lParam = NULL;
    bi.iImage = 0;
    ITEMIDLIST *id = SHBrowseForFolder(&bi);
    if (id == NULL) // cancelled
        return;
    SHGetPathFromIDList(id, folder);
    m_Target.Format(_T("%s"), folder);
    UpdateData(FALSE);
}
예제 #8
0
void CTabSample::OnBnClickedButtonSavefilepath()
{
	// TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë
	// 文件夹选择对话框

	char szDir[MAX_PATH];

	BROWSEINFO bi;

	ITEMIDLIST *pidl;

	bi.hwndOwner = this->m_hWnd; // 指定父窗口,在对话框显示期间,父窗口将被禁用 


	bi.pidlRoot = NULL; // 如果指定NULL,就以“桌面”为根 

	bi.pszDisplayName = szDir; 

	bi.lpszTitle = "请选择采样数据存储目录"; // 这一行将显示在对话框的顶端 

	bi.ulFlags = BIF_STATUSTEXT | BIF_USENEWUI | BIF_RETURNONLYFSDIRS;

	bi.lpfn = NULL;

	bi.lParam = 0;

	bi.iImage = 0;

	pidl = SHBrowseForFolder(&bi);

	if(pidl == NULL) 
	{
		return;
	}
	if(!SHGetPathFromIDList(pidl, szDir))
	{	
		return;
	}
	else
	{
		m_csSaveFilePath = szDir;
	}
}
예제 #9
0
void ConfigDlg::OnPath() 
{
    
    BROWSEINFO bi = {0};
    bi.hwndOwner = m_hWnd;
    bi.lpfn = BrowseCallbackProc;
    bi.ulFlags = BIF_RETURNONLYFSDIRS|BIF_EDITBOX ;
    LPITEMIDLIST pIt= SHBrowseForFolder( &bi );
    if( pIt )
    {
        // Set the new path as the selected folder and refresh
        TCHAR tcPath[ MAX_PATH ];
        if( SHGetPathFromIDList( pIt, tcPath ))
        {
            m_List.InsertItem( 0, tcPath );
            m_bChanged = true;
        }
    }
}
예제 #10
0
// 选择文件存储路径
void CSaveFile::OnSelectSaveFilePath(void)
{
	char szDir[MAX_PATH];

	BROWSEINFO bi;

	ITEMIDLIST *pidl;

	bi.hwndOwner = m_hWnd; // 指定父窗口,在对话框显示期间,父窗口将被禁用 


	bi.pidlRoot = NULL; // 如果指定NULL,就以“桌面”为根 

	bi.pszDisplayName = szDir; 

	bi.lpszTitle = "请选择数据存储目录"; // 这一行将显示在对话框的顶端 

	bi.ulFlags = BIF_STATUSTEXT | BIF_USENEWUI | BIF_RETURNONLYFSDIRS;

	bi.lpfn = NULL;

	bi.lParam = 0;

	bi.iImage = 0;

	pidl = SHBrowseForFolder(&bi);

	if(pidl == NULL) 
	{
		return;
	}
	if(!SHGetPathFromIDList(pidl, szDir))
	{	
		return;
	}
	else
	{
		m_csSaveFilePath = szDir;
	}
	pidl = NULL;
	delete pidl;
}
예제 #11
0
char *askcdstring(const char *question, const char *default_str)
{
    LPMALLOC g_pMalloc;
    BROWSEINFO bi;
    LPITEMIDLIST pidlBrowse;
    browserInfo info;
    OSVERSIONINFOEX osvi;

    strncpy(info.question, question, 40);
    strncpy(info.default_str, default_str, MAX_PATH);

    /* Get the shell's allocator. */
    if (!SUCCEEDED(SHGetMalloc(&g_pMalloc))) return NULL;

    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    GetVersionEx((OSVERSIONINFO *)&osvi);

    ZeroMemory(&bi, sizeof(bi));
    bi.hwndOwner = 0;
    if(osvi.dwMajorVersion >= 6) { /* future proof */
	/* CSIDL_DESKTOP gets mapped to the User's desktop in Vista
	   (a bug).  SHGetFolderLocation is Win2k or later */
	if (!SUCCEEDED(SHGetFolderLocation(NULL, CSIDL_DRIVES, NULL, 0,
					   (LPITEMIDLIST *) &bi.pidlRoot)))
	    return NULL;
    }  /* else it is 0, which is CSIDL_DESKTOP */
    bi.pszDisplayName = strbuf;
    bi.lpszTitle = question;
    bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI;
    bi.lpfn = (BFFCALLBACK) InitBrowseCallbackProc;
    bi.lParam = (LPARAM) &info;

    /* Browse for a folder and return its PIDL. */
    pidlBrowse = SHBrowseForFolder(&bi);
    if (pidlBrowse != NULL) {
	SHGetPathFromIDList(pidlBrowse, strbuf);
	g_pMalloc->lpVtbl->Free(g_pMalloc, pidlBrowse);
	if (strbuf[0])
	    return strbuf;
    }
    return NULL;
}
예제 #12
0
/*!
	ディレクトリ選択ダイアログの表示
	@param[in]	hWnd		親ウインドウのハンドル
	@param[in]	ptSelFolder	ディレクトリ名を入れるバッファへのポインター
	@param[in]	cchLen		バッファの文字数。バイト数じゃないぞ
	@return		非0:ディレクトリとった 0:キャンセルした
*/
BOOLEAN SelectDirectoryDlg( HWND hWnd, LPTSTR ptSelFolder, UINT_PTR cchLen )
{
	BROWSEINFO		stBrowseInfo;
	LPITEMIDLIST	pstItemIDList;
	TCHAR	atDisplayName[MAX_PATH];

	if( !(ptSelFolder) )	return FALSE;
	ZeroMemory( ptSelFolder, sizeof(TCHAR) * cchLen );

	//	BROWSEINFO構造体に値を設定
	stBrowseInfo.hwndOwner		 = hWnd;	//	ダイアログの親ウインドウのハンドル
	stBrowseInfo.pidlRoot		 = NULL;	//	ルートディレクトリを示すITEMIDLISTのポインタ・NULLの場合デスクトップ
	stBrowseInfo.pszDisplayName	 = atDisplayName;	//	選択されたディレクトリ名を受け取るバッファのポインタ
	stBrowseInfo.lpszTitle		 = TEXT("AAの入ってるディレクトリを選択するのー!");	//	ツリービューの上部に表示される文字列
	stBrowseInfo.ulFlags		 = BIF_RETURNONLYFSDIRS;	//	表示されるディレクトリの種類を示すフラグ
	stBrowseInfo.lpfn			 = NULL;		//	BrowseCallbackProc関数のポインタ
	stBrowseInfo.lParam			 = (LPARAM)0;	//	コールバック関数に渡す値

	//	ディレクトリ選択ダイアログを表示
	pstItemIDList = SHBrowseForFolder( &stBrowseInfo );
	if( !(pstItemIDList) )
	{
		//	戻り値がNULLの場合、ディレクトリが選択されずにダイアログが閉じられたということ
		return FALSE;
	}
	else
	{
		//	ItemIDListをパス名に変換
		if( !SHGetPathFromIDList( pstItemIDList, atDisplayName ) )
		{
			//	エラー処理
			return FALSE;
		}
		//	atDisplayNameに選択されたディレクトリのパスが入ってる
		StringCchCopy( ptSelFolder, cchLen, atDisplayName );

		//	pstItemIDListを開放せしめる
		CoTaskMemFree( pstItemIDList );
	}

	return TRUE;
}
예제 #13
0
INT CALLBACK LoggingPage::dialogProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
	switch ( msg )
	{
		case WM_COMMAND:
		{
			if ( HIWORD(wParam)==EN_CHANGE )
			{
				if ( IsWindowVisible(hWnd) ) {
					SendMessage(GetParent(hWnd),UWM_SETTINGS_CHANGED,NULL,NULL);
				}
			}

			switch ( wParam )
			{
				case IDC_BUTTON_BROWSE:
				{
					char path[MAX_PATH] = {0};

					BROWSEINFO bi = {0};
					bi.hwndOwner = hWnd;
					
					LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
					if ( pidl!=NULL ) {
						SHGetPathFromIDList(pidl,path);
						SetWindowText(m_hEditPath,path);
					}

					IMalloc *pMalloc = NULL;
					if ( SUCCEEDED(SHGetMalloc(&pMalloc)) ) {
						pMalloc->Free(pidl);
						pMalloc->Release();
					}
				}
				break;
			}
		}
		break;
	}

	return 0;
}
예제 #14
0
WStringAutoPtr SelectFolder ( WStringAutoPtr prompt )
{
	BROWSEINFO browse_info = { 0 };
	browse_info.hwndOwner = GetActiveWindow();
	browse_info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI | BIF_NONEWFOLDERBUTTON;
    browse_info.lpszTitle = prompt->c_str();

    LPITEMIDLIST item_list = SHBrowseForFolder ( &browse_info );
	
	// if the user hasn't cancelled the dialog get the path to the folder

    wchar_t path[MAX_PATH] = L"";

	if ( item_list != 0 ) {
		SHGetPathFromIDList ( item_list, path );
	}

	return WStringAutoPtr ( new wstring ( path ) );

}	//	SelectFolder
예제 #15
0
BOOL CFileUtil::BrowseDir(CDuiString &path,HWND hwndOwner,CDuiString title)
{
	TCHAR szPathName[MAX_PATH]; 
	BROWSEINFO bInfo={0};  
	bInfo.hwndOwner=hwndOwner;//父窗口  
	bInfo.lpszTitle=title;  
	bInfo.ulFlags=BIF_RETURNONLYFSDIRS |BIF_USENEWUI/*包含一个编辑框 用户可以手动填写路径 对话框可以调整大小之类的..*/|  
		BIF_UAHINT/*带TIPS提示*/ |BIF_NONEWFOLDERBUTTON /*不带新建文件夹按钮*/;  
	LPITEMIDLIST lpDlist;  
	lpDlist=SHBrowseForFolder(&bInfo);  
	if (lpDlist!=NULL)//单击了确定按钮  
	{  
		SHGetPathFromIDList(lpDlist,szPathName); 
		path.Format(_T("%s"),szPathName);  
		return TRUE;
	}else
	{
		return FALSE;
	}
}
void CProjectSettingsDlg::OnBrowseDirBtn() 
{
	UpdateData(TRUE);
	BROWSEINFO bi;
	bi.hwndOwner = m_hWnd;
	bi.pidlRoot = 0;
	bi.lpszTitle = "Select Project Working Directory";
	bi.lpfn = 0;
	bi.ulFlags = BIF_USENEWUI|BIF_BROWSEINCLUDEFILES;
	char Path[MAX_PATH+1];
	bi.pszDisplayName = Path;
	LPITEMIDLIST pidlFolder = SHBrowseForFolder(&bi);
	if (pidlFolder)
	{
		SHGetPathFromIDList(pidlFolder, Path);
		m_WorkingDir = Path;

		UpdateData(FALSE);
	}
}
예제 #17
0
void COspdemoserverDlg::OnBtnFolder() 
{
	// TODO: Add your control notification handler code here
	BROWSEINFO bInfo;
	ZeroMemory(&bInfo, sizeof(bInfo));
	bInfo.hwndOwner =GetSafeHwnd();
	bInfo.lpszTitle = _T("请选择文件存放路径: ");
	bInfo.ulFlags = BIF_RETURNONLYFSDIRS; 

	LPITEMIDLIST lpDlist; //用来保存返回信息的IDList
	lpDlist = SHBrowseForFolder(&bInfo) ; //显示选择对话框
	if(lpDlist != NULL) //用户按了确定按钮
	{
		TCHAR chPath[MAX_PATH]; //用来存储路径的字符串
		SHGetPathFromIDList(lpDlist, chPath);//把项目标识列表转化成字符串
		m_strFilePath = chPath; //将TCHAR类型的字符串转换为CString类型的字符串
		//MessageBox(m_strFilePath);
		UpdateData(FALSE);
	}
}
예제 #18
0
void CTestModeDlg::OnBnClickedBtnTestBowser()
{
    BROWSEINFO bInfo;
    ZeroMemory(&bInfo, sizeof(bInfo));
    bInfo.hwndOwner =GetSafeHwnd();
    bInfo.lpszTitle = _T("请选测试图片所在文件夹的路径: ");
    bInfo.ulFlags = BIF_RETURNONLYFSDIRS;

    LPITEMIDLIST lpDlist; //用来保存返回信息的IDList
    lpDlist = SHBrowseForFolder(&bInfo) ; //显示选择对话框
    if(lpDlist != NULL) //用户按了确定按钮
    {
        TCHAR chPath[MAX_PATH]; //用来存储路径的字符串
        SHGetPathFromIDList(lpDlist, chPath);//把项目标识列表转化成字符串
        m_strTestPicFolderPath = chPath; //将TCHAR类型的字符串转换为CString类型的字符串

        GetDlgItem(IDC_EDIT_TEST__LIB)->SetWindowText(m_strTestPicFolderPath);
        UpdateData(FALSE);
    }
}
예제 #19
0
int BrowseForFolder(HWND hwnd, TCHAR *szPath)
{
    BROWSEINFO bi = {0};
    LPITEMIDLIST pidlResult;

    bi.hwndOwner = hwnd;
    bi.pszDisplayName = szPath;
    bi.lpszTitle = TranslateT("Select folder");
    bi.ulFlags = BIF_NEWDIALOGSTYLE|BIF_EDITBOX|BIF_RETURNONLYFSDIRS;				// Use this combo instead of BIF_USENEWUI
    bi.lpfn = BrowseCallbackProc;
    bi.lParam = (LPARAM)szPath;

    pidlResult = SHBrowseForFolder(&bi);
    if (pidlResult) {
        SHGetPathFromIDList(pidlResult, szPath);
        lstrcat(szPath, _T("\\"));
        CoTaskMemFree(pidlResult);
    }
    return pidlResult != NULL;
}
예제 #20
0
bool TBrowseForDirectory::Execute()
{
	// Make directory available for eccBrowseCallbackProc():
	FBfdSelectedDirectory = Directory;

	// Create and clear BROWSEINFO object:
	BROWSEINFO BrowsingInfo;
	memset(&BrowsingInfo, 0, sizeof(BROWSEINFO));
	char dir[MAX_PATH];

	BrowsingInfo.hwndOwner      = Handle;
	BrowsingInfo.pszDisplayName = dir;
	BrowsingInfo.ulFlags        = FFlags;
	BrowsingInfo.lpszTitle      = Title.c_str();
	BrowsingInfo.lpfn           = eccBrowseCallbackProc;

	// Do the browsing, BIF_NEWDIALOGSTYLE (part of BIF_USENEWUI) requires Ole(Un)Initialize:
	if (FFlags & BIF_NEWDIALOGSTYLE)
		OleInitialize(NULL);
	else
		CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
	LPITEMIDLIST pidl = SHBrowseForFolder(&BrowsingInfo);
	if (FFlags & BIF_NEWDIALOGSTYLE)
		OleUninitialize();
	else
		CoUninitialize();

	// Retrieve selected folder:
	if (pidl)
	{
		char path[MAX_PATH] = "";
		SHGetPathFromIDList(pidl, path);
		Directory = IncludeTrailingBackslash(path);
		return true;
	}
	else // Cancel is pressed:
	{
		Directory = "";
		return false;
	}
}
예제 #21
0
void CSoliDire::extract_all_files()
{
	if (!is_packed() || !m_DirTree->m_pRoot)
		return;


	CFile ifile;

	if (ifile.Open(GetPathName(), CFile::modeRead | CFile::shareDenyWrite))
	{
		BROWSEINFO bi;
		ZeroMemory(&bi,sizeof(BROWSEINFO));
		LPMALLOC pMalloc;
		LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
		TCHAR * pth = new TCHAR[MAX_PATH];
		ZeroMemory(pth, MAX_PATH);
		if(pidl != NULL)
		{
			SHGetPathFromIDList(pidl,pth);
			if(SUCCEEDED(SHGetMalloc(&pMalloc)))//pidl指向的对象用完应该释放,之前忽略了
			{
				pMalloc->Free(pidl);
				pMalloc->Release();
			}
			CString path(pth);
			if (path != "")
			{
				n = 0;
				if (path.Right(1) != "\\")
					path += "\\";
				extract_all_files(m_DirTree->m_pRoot, &ifile, path);
				printf ("All(%d) files extracted successfuly.\n", m_DirTree->get_filenum());
			}
			else
				printf("Canceled.\n");
		}


	
	}
}
예제 #22
0
char* osinterface_open_directory_browser(char *title) {
	BROWSEINFO      bi;
	char            pszBuffer[MAX_PATH];
	LPITEMIDLIST    pidl;
	LPMALLOC        lpMalloc;

	// Initialize COM
	if (FAILED(CoInitializeEx(0, COINIT_APARTMENTTHREADED))) {
		MessageBox(NULL, _T("Error opening browse window"), _T("ERROR"), MB_OK);
		CoUninitialize();
		return 0;
	}

	// Get a pointer to the shell memory allocator
	if (FAILED(SHGetMalloc(&lpMalloc))) {
		MessageBox(NULL, _T("Error opening browse window"), _T("ERROR"), MB_OK);
		CoUninitialize();
		return 0;
	}

	bi.hwndOwner = NULL;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = pszBuffer;
	bi.lpszTitle = _T(title);
	bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
	bi.lpfn = NULL;
	bi.lParam = 0;

	char *outPath = "C:\\";

	if (pidl = SHBrowseForFolder(&bi)) {
		// Copy the path directory to the buffer
		if (SHGetPathFromIDList(pidl, pszBuffer)) {
			// Store pszBuffer (and the path) in the outPath
			outPath = (char*) malloc(strlen(pszBuffer)+1);
			strcpy(outPath, pszBuffer);
		}
	}
	CoUninitialize();
	return outPath;
}
예제 #23
0
void CFileListView::ExtractSelect()
{
	UInt32 nIndex;
	FileInfo *info = NULL;
	char szPath[MAX_PATH];

	if(m_pArchive == NULL)
		return;

	nIndex = GetCurrentSelected();
	if(nIndex < m_FileStack.back()->Chlids.size())
		info = &(m_FileStack.back()->Chlids[nIndex]);

	if(info != NULL)
	{
		if(info->nFileSize > 0)
		{
			GetCurrentFileName(nIndex, szPath, MAX_PATH);
			ExtractFile(szPath);
		}
		else
		{
			BROWSEINFO bi; 
			bi.hwndOwner      = m_hWnd;
			bi.pidlRoot       = NULL;
			bi.pszDisplayName = NULL; 
			bi.lpszTitle      = TEXT("请选择文件夹"); 
			bi.ulFlags        = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
			bi.lpfn           = NULL; 
			bi.lParam         = 0;
			bi.iImage         = 0; 

			LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
			if (pidl == NULL)
				return;

			if (SHGetPathFromIDList(pidl, szPath))
				ExtractFolder(info, NULL, szPath);
		}
	}
}
예제 #24
0
LRESULT OptionsWindow::onCommand(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	wmId = LOWORD(wParam);
	wmEvent = HIWORD(wParam);
	BROWSEINFO bi = { 0 };
	bi.lpszTitle = _T("Browse for folder");
	LPITEMIDLIST pidl;

	// Parse the menu selections:
	switch (wmId) {
		case IDM_OK:
			saveOptions();
			PostMessage(_parent->getHandle(), UWM_CLOSE_OPTIONS, 0, 0);
			break;
		case IDM_CANCEL:
			PostMessage(_parent->getHandle(), UWM_CLOSE_OPTIONS, 0, 0);
			break;
		case IDM_APLLY:
			saveOptions();
			break;
		case IDM_BROWSE:
			pidl = SHBrowseForFolder(&bi);
			if (pidl != 0) {
				TCHAR path[MAX_PATH];
				if (SHGetPathFromIDList(pidl, path)) {
					_savePathEditBox->setWindowText(path);
				}

				IMalloc *imalloc = 0;
				if (SUCCEEDED(SHGetMalloc(&imalloc))) {
					imalloc->Free(pidl);
					imalloc->Release();
				}
			}
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
// browse for a folder
bool CBrowseForFolder::GetFolder(CString &returnPath)
{
	LPITEMIDLIST pidlRoot = NULL;
	// get the pidl of the root 
	GetPidl(strDirRoot, pidlRoot);
	
	TCHAR strBuff[MAX_PATH + 1];
	
	returnPath.Empty();
	LPMALLOC pMalloc;
	if (SUCCEEDED(SHGetMalloc(&pMalloc)))
	{
		BROWSEINFO brInfo= 
		{
			hWndOwner, 
				pidlRoot, 
				strBuff, 
				strTitle,
				flags,
				BrowseCallbackProc,
				(LPARAM)&strStartupDir,
				Image
		};
		LPITEMIDLIST pidl = SHBrowseForFolder(&brInfo);
		
		if (pidl)
		{
			SHGetPathFromIDList(pidl, strBuff);
			pMalloc->Free(pidl);
			returnPath = strBuff;
		}
		if (pidlRoot) 
			pMalloc->Free(pidlRoot);
		pMalloc->Release();					
	}
	
	if (!returnPath.IsEmpty())
		return true;
	else 
		return false;
}
예제 #26
0
//////////////////
// Browse for folder. Args are same as for SHBrowseForFolder, but with extra
// bFilter that tells whether to do custom filtering. Note this requires
// BIF_NEWDIALOGSTYLE, which is inconsistent with some other flags--be
// careful!
//
LPCITEMIDLIST CFolderDialog::BrowseForFolder(LPCTSTR title, UINT flags,
	LPCITEMIDLIST root, BOOL bFilter)
{
	//BFTRACE(_T("CFolderDialog::BrowseForFolder\n"));
	TCHAR* buf = m_sDisplayName.GetBuffer(MAX_PATH);
	m_brinfo.pidlRoot = root;
	m_brinfo.pszDisplayName = buf;
	m_brinfo.lpszTitle = title;
	m_brinfo.ulFlags = flags;
	m_brinfo.lpfn = CallbackProc;
	m_brinfo.lParam = (LPARAM)this;

	// filtering only supported for new-style dialogs
	m_bFilter = bFilter;
	ASSERT(!bFilter||(m_brinfo.ulFlags & BIF_NEWDIALOGSTYLE));

	LPCITEMIDLIST pidl = SHBrowseForFolder(&m_brinfo); // do it
	m_sDisplayName.ReleaseBuffer();

	return pidl;
}
void Ckgb_arch_decompressDlg::OnBnClickedBbrowse2()
{
	BROWSEINFO bInfo;
	bInfo.hwndOwner = m_hWnd;
	bInfo.lpfn = NULL;
	bInfo.lParam = NULL;
	bInfo.lpszTitle = loadString(IDS_CHOOSE_DIR2DECOMPRESS);
	bInfo.pidlRoot = NULL;
	bInfo.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
	bInfo.pszDisplayName = NULL;//foldername;

	LPITEMIDLIST pidl;

	if((pidl = SHBrowseForFolder(&bInfo)) != NULL){
		char buff[MAX_PATH];
		SHGetPathFromIDList(pidl, buff);
		//GetCurrentDirectory(MAX_PATH, foldername);
		//eDestination.SetWindowText(foldername);
		eDestination.SetWindowText(buff);
	}
}
void CFormatRecoveryDlg::OnRecoverpos() 
{
	// TODO: Add your control notification handler code here
	BROWSEINFO stInfo = {NULL}; 
	LPCITEMIDLIST pIdlst; 
	CHAR szPath[MAX_PATH]; 
	
#define BIF_NEWDIALOGSTYLE      0x00000040 
#define BIF_USENEWUI            (BIF_NEWDIALOGSTYLE | BIF_EDITBOX)
	
	stInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; 
	stInfo.lpszTitle= "请选择路径:"; 
	pIdlst = SHBrowseForFolder(&stInfo); 
	if(!pIdlst || !SHGetPathFromIDList(pIdlst, szPath)) 
		return ;
	int len=_tcslen(szPath);
	if(szPath[len-1] == '\\')
		szPath[len-1]='\0';

	SetDlgItemText(IDC_SAVEPOS,szPath);
}
예제 #29
0
// フォルダ参照ダイアログ
bool BrowseFolderDialog(HWND hwndOwner,LPTSTR pszDirectory,LPCTSTR pszTitle)
{
	BROWSEINFO bi;
	PIDLIST_ABSOLUTE pidl;
	BOOL fRet;

	bi.hwndOwner=hwndOwner;
	bi.pidlRoot=NULL;
	bi.pszDisplayName=pszDirectory;
	bi.lpszTitle=pszTitle;
	// BIF_NEWDIALOGSTYLE を使ってるが、CoInitialize は TVTest 本体で呼んでいるので不要
	bi.ulFlags=BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
	bi.lpfn=BrowseFolderCallback;
	bi.lParam=reinterpret_cast<LPARAM>(pszDirectory);
	pidl=SHBrowseForFolder(&bi);
	if (pidl==NULL)
		return false;
	fRet=SHGetPathFromIDList(pidl,pszDirectory);
	CoTaskMemFree(pidl);
	return fRet==TRUE;
}
예제 #30
0
void CstubDlg::OnBnClickedButton1()
{
	BROWSEINFO bInfo;
	bInfo.hwndOwner = m_hWnd;
	bInfo.lpfn = NULL;
	bInfo.lParam = NULL;
	bInfo.lpszTitle = L"Please select destination";
	bInfo.pidlRoot = NULL;
	bInfo.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
	bInfo.pszDisplayName = NULL;//foldername;

	LPITEMIDLIST pidl;

	if((pidl = SHBrowseForFolder(&bInfo)) != NULL){
		wchar_t buff[MAX_PATH];
		SHGetPathFromIDList(pidl, buff);
		//GetCurrentDirectory(MAX_PATH, foldername);
		//eDestination.SetWindowText(foldername);
		eDestination.SetWindowText(buff);
	}
}