void CSettingsDictPage::OnBrowseLocation()
{
	TCHAR szPath[_MAX_PATH];
	CString strTitle = LoadString(IDS_DICT_LOCATION_PROMPT);

	BROWSEINFO info;
	ZeroMemory(&info, sizeof(info));
	info.hwndOwner = m_hWnd;
	info.pszDisplayName = szPath;
	info.lpszTitle = strTitle;
	info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_VALIDATE | BIF_USENEWUI;
	info.lpfn = BrowseCallbackProc;
	info.lParam = (LPARAM) this;

	LPITEMIDLIST pItem = SHBrowseForFolder(&info);
	if (pItem == NULL)
		return;

	if (SHGetPathFromIDList(pItem, szPath))
	{
		PathRemoveBackslash(szPath);
		m_strDictLocation = szPath;
		UpdateData(false);
	}

	LPMALLOC pMalloc;
	if (SUCCEEDED(SHGetMalloc(&pMalloc)))
		pMalloc->Free(pItem);
}
 std::string BrowseFolder()
{
	TCHAR path[MAX_PATH];

	BROWSEINFO bi = { 0 };
	bi.lpszTitle = ("Please select the folder path...");

	LPITEMIDLIST pidl = SHBrowseForFolder(&bi);

	if (pidl != 0)
	{
		//get the name of the folder and put it in path
		SHGetPathFromIDList(pidl, path);

		//free memory used
		IMalloc * imalloc = 0;
		if (SUCCEEDED(SHGetMalloc(&imalloc)))
		{
			imalloc->Free(pidl);
			imalloc->Release();
		}
		//std::wstring arr_w(path);
		//std::string paths(arr_w.begin(), arr_w.end());
		return path;
	}

	return "";
}
Beispiel #3
0
static BOOL BrowseForFolder(HWND hwnd, const WCHAR *lpszInitialFolder, const WCHAR *lpszCaption, WCHAR *lpszBuf, DWORD dwBufSize)
{
    if (lpszBuf == nullptr || dwBufSize < MAX_PATH)
        return FALSE;

    BROWSEINFO bi = { 0 };
    bi.hwndOwner = hwnd;
    bi.ulFlags   = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
    bi.lpszTitle = lpszCaption;
    bi.lpfn      = BrowseCallbackProc;
    bi.lParam    = (LPARAM)lpszInitialFolder;

    BOOL ok = FALSE;
    LPITEMIDLIST pidlFolder = SHBrowseForFolder(&bi);
    if (pidlFolder) {
        ok = SHGetPathFromIDList(pidlFolder, lpszBuf);

        IMalloc *pMalloc = nullptr;
        if (SUCCEEDED(SHGetMalloc(&pMalloc)) && pMalloc) {
            pMalloc->Free(pidlFolder);
            pMalloc->Release();
        }
    }

    return ok;
}
//----------------------------------------------------------------------------------------
static void GetWindowsFolder(int folder, nsFileSpec& outDirectory)
//----------------------------------------------------------------------------------------
{

    if (gGetSpecialPathProc) {
        TCHAR path[MAX_PATH];
        HRESULT result = gGetSpecialPathProc(NULL, path, folder, true);
        
        if (!SUCCEEDED(result)) 
            return;

        // Append the trailing slash
        int len = PL_strlen(path);
        if (len>1 && path[len-1] != '\\') 
        {
            path[len]   = '\\';
            path[len + 1] = '\0';
        }
        outDirectory = path;
        return;
    }

    LPMALLOC pMalloc = NULL;
    LPSTR pBuffer = NULL;
    LPITEMIDLIST pItemIDList = NULL;
    int len;
 
    // Get the shell's allocator. 
    if (!SUCCEEDED(SHGetMalloc(&pMalloc))) 
        return;

    // Allocate a buffer
    if ((pBuffer = (LPSTR) pMalloc->Alloc(MAX_PATH + 2)) == NULL) 
        return; 
 
    // Get the PIDL for the folder. 
    if (!SUCCEEDED(SHGetSpecialFolderLocation( 
            NULL, folder, &pItemIDList)))
        goto Clean;
 
    if (!SUCCEEDED(SHGetPathFromIDList(pItemIDList, pBuffer)))
        goto Clean;

    // Append the trailing slash
    len = PL_strlen(pBuffer);
    pBuffer[len]   = '\\';
    pBuffer[len + 1] = '\0';

    // Assign the directory
    outDirectory = pBuffer;

Clean:
    // Clean up. 
    if (pItemIDList)
        pMalloc->Free(pItemIDList); 
    if (pBuffer)
        pMalloc->Free(pBuffer); 

	pMalloc->Release();
} // GetWindowsFolder
Beispiel #5
0
//////////////////
// Free PIDL using shell's IMalloc
//
void CFolderDialog::FreePIDL(LPCITEMIDLIST pidl)
{
	CComQIPtr<IMalloc> iMalloc;	// shell's IMalloc
	HRESULT hr = SHGetMalloc(&iMalloc);
	ASSERT(SUCCEEDED(hr));
	iMalloc->Free((void*)pidl);
}
Beispiel #6
0
int folder_dialog(HWND hwnd, char *path)
{
	BROWSEINFO BINFO;
	LPITEMIDLIST pidl;
	LPMALLOC pMalloc;
	int res = 0;

	if (SUCCEEDED(SHGetMalloc(&pMalloc)))
	{
		memset(&BINFO, 0, sizeof(BINFO));
		BINFO.hwndOwner = hwnd;
#ifdef CHINESE
		BINFO.lpszTitle = "选择ROM文件夹";
#else
		BINFO.lpszTitle = "Select ROM folder";
#endif
		BINFO.ulFlags = BIF_RETURNONLYFSDIRS;

		pidl = SHBrowseForFolder(&BINFO);
		if (pidl)
		{
			res = SHGetPathFromIDList(pidl, path);
			IMalloc_Free(pMalloc, pidl);
		}
		IMalloc_Release(pMalloc);
	}
	return res;
}
Beispiel #7
0
   std::string FileDialogFolder( const std::string &title, const std::string &text ) {

      char path[MAX_PATH];
       BROWSEINFO bi = { 0 };
       bi.lpszTitle = ("All Folders Automatically Recursed.");
       LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );

       if ( pidl != 0 ) {
           // get the name of the folder and put it in path
           SHGetPathFromIDList ( pidl, path );


           // free memory used
           IMalloc * imalloc = 0;
           if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
           {
               imalloc->Free ( pidl );
               imalloc->Release ( );
           }

           return std::string(path);
       }
      
      return ""; 
   }
Beispiel #8
0
static char *win_special_path (int folder)
{
    TCHAR dpath[MAX_PATH];
    LPITEMIDLIST id_list;
    DWORD result;
    LPMALLOC allocator;
    char *ret = NULL;

    if (SHGetSpecialFolderLocation(NULL, folder | CSIDL_FLAG_CREATE, 
				   &id_list) != S_OK) {
	return NULL;
    }

    result = SHGetPathFromIDList(id_list, dpath);

    if (result) {
	ret = gretl_strdup(dpath);
    }

    if (SHGetMalloc(&allocator) == S_OK) {
	allocator->lpVtbl->Free(allocator, id_list);
	allocator->lpVtbl->Release(allocator);
    }

    return ret;
}
CString CRemotePlaybackDlg::BrowseForFolder(HWND hWnd)
{
	TCHAR szTitle[] = _T("Select a folder");
	TCHAR szDisplayName[MAX_PATH] = _T("");
	TCHAR szPath[MAX_PATH] = _T("");
	BROWSEINFO bi;
	
	bi.hwndOwner= hWnd;
	bi.pidlRoot= NULL;
	bi.lpszTitle= szTitle;
	bi.pszDisplayName = szDisplayName;
	bi.ulFlags= BIF_RETURNONLYFSDIRS;
	bi.lpfn= NULL;
	bi.lParam= 0;
	
	LPITEMIDLIST pItemIDList = SHBrowseForFolder( &bi );
	if( pItemIDList )
	{
		SHGetPathFromIDList(pItemIDList,szPath);
		
		IMalloc *pMalloc;
		if( SHGetMalloc( &pMalloc ) != NOERROR )
		{
			//TRACE( "Failed to get pointer to shells task allocator" ) ;
			return szPath;
		}
		pMalloc->Free( pItemIDList );
		if( pMalloc )
			pMalloc->Release();
	}
	return szPath;
}
Beispiel #10
0
//------------------------------------------------------------------------------
void __fastcall TPrefsForm::BrowseButtonClick(TObject* Sender) {
  BROWSEINFO    info;
  char          szDir[MAX_PATH];
  char          szDisplayName[MAX_PATH];
  LPITEMIDLIST  pidl;
  LPMALLOC      pShellMalloc;

  if(SHGetMalloc(&pShellMalloc) == NO_ERROR) {
    memset(&info, 0x00, sizeof(info));
    info.hwndOwner = Handle;
    info.pidlRoot  = 0;
    info.pszDisplayName = szDisplayName;
    info.lpszTitle = LMessagesOpt.SelectFolder;
    info.ulFlags = BIF_NEWDIALOGSTYLE; //BIF_RETURNONLYFSDIRS;
    info.lpfn = 0;
    pidl = SHBrowseForFolder(&info);

    if(pidl) {
      if(SHGetPathFromIDList(pidl, szDir))
        BackupPath->Text = szDir;

      pShellMalloc->Free(pidl);
    }

    pShellMalloc->Release();
  }
}
Beispiel #11
0
//---------------------------------------------------------------------------
void __fastcall TConfigForm::btnBrowseClick(TObject *Sender)
{
	WCHAR buf[MAX_PATH];
	BROWSEINFOW bi;
	PIDLIST_ABSOLUTE pidl;

	wcscpy_s(buf, MAX_PATH, hAddressBook->Text.c_str());

	bi.hwndOwner = this->Handle;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = buf;
	bi.lpszTitle = _(L"Choose address book location").c_str();
	bi.ulFlags = BIF_EDITBOX;
	bi.lpfn = NULL;
	bi.lParam = NULL;
	bi.iImage = 0;

	CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
	if ((pidl = SHBrowseForFolderW(&bi)) != NULL) {
		if (SHGetPathFromIDListW(pidl, buf))
			hAddressBook->Text = buf;
		IMalloc *pMalloc = NULL;
		SHGetMalloc(&pMalloc);
		pMalloc->Free(pidl);
		pMalloc->Release();
	}
	CoUninitialize();
}
Beispiel #12
0
void CSnapperOptions::OnBnClickedBrowseNotebook()
{
	BROWSEINFO sBi = { 0 };
	/*
    sBi.lpszTitle = TEXT("Select Notebook(s)");
	sBi.hwndOwner = m_hWndTop;
	sBi.iImage = 
	*/
    LPITEMIDLIST pIdl = SHBrowseForFolder ( &sBi );
    if ( pIdl != NULL )
    {
        // get the name of the folder
        TCHAR pszNotebookPath[MAX_PATH];
        if ( SHGetPathFromIDList ( pIdl, pszNotebookPath ) )
        {
			m_strNotebookPath = pszNotebookPath;
			m_bUpdateHotlists = TRUE;
			UpdateData(FALSE);
        }

        // free memory 
        IMalloc * piMalloc = NULL;
        if ( SUCCEEDED( SHGetMalloc ( &piMalloc )) )
        {
            piMalloc->Free ( pIdl );
            piMalloc->Release ( );
        }

    }
	
}
Beispiel #13
0
rt_private DWORD WINAPI c_browse_for_folder (LPVOID param)
	/* Main routine of thread that will create BrowseForFolder dialog. */
{
	LPITEMIDLIST id_list;
	struct EIF_BROWSE *browse = (struct EIF_BROWSE *) param;
	HRESULT hr;
	LPMALLOC imalloc;

		/* First initialize COM with single threaded appartment. */
	hr = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);

	id_list = SHBrowseForFolder (browse->info);

	if (id_list) {
		if (SHGetPathFromIDList (id_list, browse->name)) {
			hr = SHGetMalloc (&imalloc);
			if (hr == NOERROR) {
				imalloc->lpVtbl->Free (imalloc, id_list);
			}
		}
	} else {
		browse->cancelled = 1;
	}

		/* No need for COM anymore */
	CoUninitialize();
	ExitThread(0);

	return 0;
}
Beispiel #14
0
/*
	ディレクトリダイアログ用汎用ルーチン
*/
void BrowseDirDlg(TWin *parentWin, UINT editCtl, char *title)
{ 
	IMalloc			*iMalloc = NULL;
	BROWSEINFO		brInfo;
	LPITEMIDLIST	pidlBrowse;
	char			fileBuf[MAX_PATH];

	parentWin->GetDlgItemText(editCtl, fileBuf, sizeof(fileBuf));
	if (!SUCCEEDED(SHGetMalloc(&iMalloc)))
		return;

	TBrowseDirDlg	dirDlg(fileBuf);
	brInfo.hwndOwner = parentWin->hWnd;
	brInfo.pidlRoot = 0;
	brInfo.pszDisplayName = fileBuf;
	brInfo.lpszTitle = title;
	brInfo.ulFlags = BIF_RETURNONLYFSDIRS;
	brInfo.lpfn = BrowseDirDlg_Proc;
	brInfo.lParam = (LPARAM)&dirDlg;
	brInfo.iImage = 0;

	do {
		if ((pidlBrowse = ::SHBrowseForFolder(&brInfo)) != NULL) {
			if (::SHGetPathFromIDList(pidlBrowse, fileBuf))
				::SetDlgItemText(parentWin->hWnd, editCtl, fileBuf);
			iMalloc->Free(pidlBrowse);
			break;
		}
	} while (dirDlg.IsDirty());

	iMalloc->Release();
}
Beispiel #15
0
 BOOL	GetSpecialFolder(UINT SpecialFolder, CString &SpecialFolderString)

{
	HRESULT hr;

	LPITEMIDLIST pidl;

	hr = SHGetSpecialFolderLocation(NULL, SpecialFolder, &pidl);

    if(SUCCEEDED(hr))
		{
		// Convert the item ID list's binary representation into a file system path
		char szPath[_MAX_PATH];

		if(SHGetPathFromIDList(pidl, szPath))
			{
			// Allocate a pointer to an IMalloc interface
			LPMALLOC pMalloc;

			// Get the address of our task allocator's IMalloc interface
			hr = SHGetMalloc(&pMalloc);

			// Free the item ID list allocated by SHGetSpecialFolderLocation
			pMalloc->Free(pidl);

			// Free our task allocator
			pMalloc->Release();

			// Work with the special folder's path (contained in szPath)
			SpecialFolderString = szPath;	SpecialFolderString += "\\";
			return TRUE;
			}
		}
	return FALSE;
}
Beispiel #16
0
string pDialogWindow::folderSelect(Window &parent, const string &path) {
  wchar_t wfilename[PATH_MAX + 1] = L"";
  BROWSEINFO bi;
  bi.hwndOwner = &parent != &Window::None ? parent.p.hwnd : 0;
  bi.pidlRoot = NULL;
  bi.pszDisplayName = wfilename;
  bi.lpszTitle = L"";
  bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS;
  bi.lpfn = NULL;
  bi.lParam = 0;
  bi.iImage = 0;
  bool result = false;
  LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
  if(pidl) {
    if(SHGetPathFromIDList(pidl, wfilename)) {
      result = true;
      IMalloc *imalloc = 0;
      if(SUCCEEDED(SHGetMalloc(&imalloc))) {
        imalloc->Free(pidl);
        imalloc->Release();
      }
    }
  }
  if(result == false) return "";
  string name = (const char*)utf8_t(wfilename);
  if(name == "") return "";
  name.transform("\\", "/");
  if(name.endswith("/") == false) name.append("/");
  return name;
}
void SetCertDirDlg::OnBnClickedButton1()
{
	LPMALLOC pMalloc;
    
    if( SUCCEEDED( SHGetMalloc( &pMalloc ) ) ) 
    {
        TCHAR szTitle[] = _T("Choose Directory for storing certificates.");
        BROWSEINFO bi;
        ZeroMemory( &bi, sizeof( bi ) );
        bi.hwndOwner = NULL;
        bi.pszDisplayName = NULL;
        bi.lpszTitle = szTitle;
        bi.pidlRoot = NULL;
		bi.ulFlags = BIF_RETURNONLYFSDIRS;
        
        LPITEMIDLIST pidl = SHBrowseForFolder( &bi );
        if( pidl ) 
        {
            TCHAR szDir[MAX_PATH];
            if( SHGetPathFromIDList( pidl, szDir ) ) 
            {
				m_CertificatePath.SetWindowText(szDir);
				m_CertificatePath.SetFocus();
            }
            pMalloc->Free(pidl); 
            pMalloc->Release();
        }
    }
}
/* #FN#
   Responds to TVN_DELETEITEM message in order to release the memory
   allocated by the shell folders */
void
/* #AS#
   Nothing */
CShellTree::
OnDeleteShellItem(
	NMHDR   *pNMHDR, /* #IN# */
	LRESULT *pResult /* #OUT# */
)
{
	LPTVITEMDATA lptvid   = NULL;
	LPMALLOC     lpMalloc = NULL;
	HRESULT      hr;

	NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW *)pNMHDR;

	/* Let's free the memory for the TreeView item data */
	hr = SHGetMalloc( &lpMalloc );
	if( FAILED(hr) )
		return;

	lptvid = (LPTVITEMDATA)pNMTreeView->itemOld.lParam;
	lptvid->lpsfParent->Release();
	lpMalloc->Free( lptvid->lpi );
	lpMalloc->Free( lptvid->lpifq );
	lpMalloc->Free( lptvid );
	lpMalloc->Release();

} /* #OF# CShellTree::OnDeleteShellItem */
Beispiel #19
0
bool plBrowseFolder::GetFolder(char *path, const char *startPath, const char *title, HWND hwndOwner)
{
    BROWSEINFO bi;
    memset(&bi, 0, sizeof(bi));
    bi.hwndOwner    = hwndOwner;
    bi.lpszTitle    = title;
    bi.lpfn         = BrowseCallbackProc;
    bi.lParam       = (LPARAM) startPath;

    ITEMIDLIST *iil = SHBrowseForFolder(&bi);
    // Browse failed, or cancel was selected
    if (!iil)
        return false;
    // Browse succeded.  Get the path.
    else
        SHGetPathFromIDList(iil, path);

    // Free the memory allocated by SHBrowseForFolder
    LPMALLOC pMalloc;
    SHGetMalloc(&pMalloc);
    pMalloc->Free(iil);
    pMalloc->Release();

    return true;
}
Beispiel #20
0
/*
	ディレクトリダイアログ用汎用ルーチン
*/
BOOL BrowseDirDlg(TWin *parentWin, const char *title, const char *defaultDir, char *buf)
{ 
	IMalloc			*iMalloc = NULL;
	BROWSEINFOW		brInfo;
	LPITEMIDLIST	pidlBrowse;
	BOOL			ret = FALSE;
	Wstr			buf_w(MAX_PATH), defaultDir_w(MAX_PATH), title_w(title);

	if (!SUCCEEDED(SHGetMalloc(&iMalloc)))
		return FALSE;

	U8toW(defaultDir, defaultDir_w.Buf(), MAX_PATH);
	brInfo.hwndOwner = parentWin->hWnd;
	brInfo.pidlRoot = 0;
	brInfo.pszDisplayName = buf_w.Buf();
	brInfo.lpszTitle = title_w;
	brInfo.ulFlags = BIF_RETURNONLYFSDIRS;
	brInfo.lpfn = BrowseDirDlgProc;
	brInfo.lParam = (LPARAM)defaultDir_w.Buf();
	brInfo.iImage = 0;

	if ((pidlBrowse = SHBrowseForFolderV((BROWSEINFO *)&brInfo)))
	{
		ret = SHGetPathFromIDListV(pidlBrowse, buf_w.Buf());
		iMalloc->Free(pidlBrowse);
		if (ret)
			WtoU8(buf_w, buf, MAX_PATH_U8);
	}

	iMalloc->Release();
	return	ret;
}
Beispiel #21
0
bool system_alert_choose_scenario(char *chosen_dir)
{
#if defined(__WIN32__)
	BROWSEINFO bi = { 0 };
	TCHAR path[MAX_PATH];
	bi.lpszTitle = _T("Select a scenario to play:");
	bi.pszDisplayName = path;
	bi.lpfn = browse_callback_proc;
	bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | 0x00000200; // no "New Folder" button
	LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
	if (pidl)
	{
		SHGetPathFromIDList(pidl, path);
#ifdef UNICODE
		WideCharToMultiByte(CP_UTF8, 0, path, -1, chosen_dir, 256, NULL, NULL);
#else
		strncpy(chosen_dir, path, 255);
#endif
		LPMALLOC pMalloc = NULL;
		SHGetMalloc(&pMalloc);
		pMalloc->Free(pidl);
		pMalloc->Release();
		return true;
	}
#endif
	return false;
}
void choosePath( HWND parent, int hostCtlId )
{
	HWND			hostControl = GetDlgItem( parent, hostCtlId );

	BROWSEINFOW		dialog;
	wchar_t			path[MAX_PATH];    // buffer for file name

	Edit_GetText( hostControl, path, sizeof(path) );

	ZeroMemory(&dialog,sizeof(dialog));

	dialog.lpszTitle		= L"Pick a CA Path";
	dialog.hwndOwner		= parent;
	dialog.pszDisplayName	= path;

	LPITEMIDLIST pidl = SHBrowseForFolder ( &dialog );

	if ( pidl )
	{
		SHGetPathFromIDList ( pidl, path );

		Edit_SetText( hostControl, path );

		IMalloc * imalloc = 0;
		if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
		{
			imalloc->Free ( pidl );
			imalloc->Release ( );
		}
	}
}
Beispiel #23
0
const char *win_dir_chooser(const char *message, const char *fname)
{
	static char szFileName[MAX_PATH]="";
	BROWSEINFO lpbi;
	LPITEMIDLIST pidl;

	//on vide la structure lpbi
	ZeroMemory(&lpbi,sizeof(BROWSEINFO));

	//on remplit la structure avec des informations utiles
	lpbi.hwndOwner = GET_HWND;
	lpbi.lpszTitle = "Choisissez un répertoire...";
	lpbi.pszDisplayName = szFileName;

	//puis on lance le sélecteur de répertoires.
	pidl = SHBrowseForFolder(&lpbi);

	//si l'utilisateur a sélectionné un fichier
	if(pidl!=0) {
		BOOL result = SHGetPathFromIDList(pidl,szFileName);

		//désallocation de la mémoire déjà utilisée
		IMalloc * imalloc = 0;
		if(SUCCEEDED(SHGetMalloc(&imalloc))) {
			imalloc->Free(pidl);
			imalloc->Release();
		}
		//puis là on retourne le résultat: le chemin absolu
		//du répertoire sélectionné
		if(result) return szFileName;
	}

	return 0;
}
void CBitTorrentSettingsPage::OnTorrentsBrowse() 
{
	TCHAR szPath[MAX_PATH];
	LPITEMIDLIST pPath;
	LPMALLOC pMalloc;
	BROWSEINFO pBI;
		
	ZeroMemory( &pBI, sizeof(pBI) );
	pBI.hwndOwner		= AfxGetMainWnd()->GetSafeHwnd();
	pBI.pszDisplayName	= szPath;
	pBI.lpszTitle		= _T("Select folder for torrents:");
	pBI.ulFlags			= BIF_RETURNONLYFSDIRS;
	
	pPath = SHBrowseForFolder( &pBI );

	if ( pPath == NULL ) return;

	SHGetPathFromIDList( pPath, szPath );
	SHGetMalloc( &pMalloc );
	pMalloc->Free( pPath );
	pMalloc->Release();
	
	UpdateData( TRUE );
	m_sTorrentPath = szPath;
	UpdateData( FALSE );
}
bool CComDialog::PopFolderDlg(OUT char* path, IN char* title, IN BFFCALLBACK cb)
{ 
    BROWSEINFO bi;
	ZeroMemory(&bi, sizeof(BROWSEINFO));    

//初始化入口参数bi开始****************************
    bi.hwndOwner = _hwnd;//::AfxGetMainWnd()->GetSafeHwnd();
    bi.pidlRoot = NULL;
    bi.pszDisplayName = path;//此参数如为NULL则不能显示对话框
    bi.lpszTitle = title;
    bi.ulFlags = 0;
    bi.lpfn = cb;
/*    bi.iImage= IDR_MAINFRAME;*/
//初始化入口参数bi结束*****************************

    LPITEMIDLIST pIDList = SHBrowseForFolder(&bi);//调用显示选择对话框
    if (pIDList)
    {
        SHGetPathFromIDList(pIDList, path);
        //取得文件夹路径到Buffer里
		LPMALLOC lpMalloc;
		if (FAILED(SHGetMalloc(&lpMalloc))) 
			return false;
		//释放内存
		lpMalloc->Free(pIDList);
		lpMalloc->Release();

		return true;
    }
	else
	{
		return false;
	}
}
Beispiel #26
0
// only one full qualified PIDL has been passed
void CShellContextMenu::SetObjects(LPITEMIDLIST pidl)
{
	// free all allocated datas
	if (m_psfFolder && bDelete)
		m_psfFolder->Release ();
	m_psfFolder = NULL;
	FreePIDLArray (m_pidlArray);
	m_pidlArray = NULL;

		// full qualified PIDL is passed so we need
	// its parent IShellFolder interface and its relative PIDL to that
	LPITEMIDLIST pidlItem = NULL;
	SHBindToParent ((LPCITEMIDLIST) pidl, IID_IShellFolder, (void **) &m_psfFolder, (LPCITEMIDLIST *) &pidlItem);	

	m_pidlArray = (LPITEMIDLIST *) malloc (sizeof (LPITEMIDLIST));	// allocate ony for one elemnt
	m_pidlArray[0] = CopyPIDL (pidlItem);


	// now free pidlItem via IMalloc interface (but not m_psfFolder, that we need later
	LPMALLOC lpMalloc = NULL;
	SHGetMalloc (&lpMalloc);
	lpMalloc->Free (pidlItem);
	lpMalloc->Release();

	nItems = 1;
	bDelete = TRUE;	// indicates that m_psfFolder should be deleted by CShellContextMenu
}
Beispiel #27
0
bool DirectoryRefDialog(HWND hWnd,char *Result)
{
    bool r = false;
    LPMALLOC Memory;
    LPCSTR Buffer;
    LPITEMIDLIST Ret;
    LPITEMIDLIST Root;
    SHGetMalloc(&Memory);
    Buffer = (LPSTR)Memory->Alloc(1000);
    SHGetSpecialFolderLocation(hWnd,CSIDL_DESKTOP,&Root);
    ZeroMemory(&BI,sizeof(BROWSEINFO));
    BI.hwndOwner = hWnd;
    BI.pidlRoot = Root;
    BI.ulFlags = BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS;
    BI.lpszTitle = "展開先を指定してください";
    BI.pszDisplayName = (LPSTR)Buffer;
    BI.lpfn = BrowseCallbackProc;
    Ret = SHBrowseForFolder(&BI);
    if (SHGetPathFromIDList(Ret,(LPSTR)Buffer))
    {
        lstrcpy(Result,Buffer);
        r = true;
    }
    Memory->Free(Ret);
    Memory->Free(Root);
    Memory->Free((void*)Buffer);
    return r;
}
Beispiel #28
0
bool WDL_ChooseDirectory(HWND parent, const char *text, const char *initialdir, char *fn, int fnsize, bool preservecwd)
{
  char olddir[2048];
  GetCurrentDirectory(sizeof(olddir),olddir);
#ifdef _WIN32
  char name[4096];
  lstrcpyn(name,initialdir?initialdir:"",sizeof(name));
  BROWSEINFO bi={parent,NULL, name, text, BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE, WDL_BrowseCallbackProc, (LPARAM)name,};
  LPITEMIDLIST idlist = SHBrowseForFolder( &bi );
  if (idlist) 
  {
    SHGetPathFromIDList( idlist, name );        
    IMalloc *m;
    SHGetMalloc(&m);
    m->Free(idlist);
    lstrcpyn(fn,name,fnsize);
    return true;
  }
  return false;

#else
  bool r = BrowseForDirectory(text,initialdir,fn,fnsize);
  if (preservecwd) SetCurrentDirectory(olddir);
  return r;
#endif
}
Beispiel #29
0
//Pabs inserted
//Parts copied from compiler docs - search for ITEMIDLIST in title in msdn
//Adapted from Q132750:"HOWTO: Convert a File Path to an ITEMIDLIST" in the Knowledge Base
STDAPI PathsEqual(LPCTSTR p0, LPCTSTR p1)
{
	LPSHELLFOLDER pFolder;
	HRESULT hr;
	if (SUCCEEDED(hr = SHGetDesktopFolder(&pFolder)))
	{
		LPITEMIDLIST pidl[2] = { NULL, NULL };
		ULONG chEaten;//only needed by parse dispname
		// Convert the paths to ITEMIDLISTs.
		if (SUCCEEDED(hr = pFolder->ParseDisplayName(NULL, NULL,
				const_cast<LPOLESTR>(&*static_cast<T2W>(p0)), &chEaten, &pidl[0], NULL)) &&
			SUCCEEDED(hr = pFolder->ParseDisplayName(NULL, NULL,
				const_cast<LPOLESTR>(&*static_cast<T2W>(p1)), &chEaten, &pidl[1], NULL)))
		{
			hr = pFolder->CompareIDs(0, pidl[0], pidl[1]);
		}

		//free ITEMIDLISTs
		IMalloc* pm;
		SHGetMalloc(&pm);
		pm->Free(pidl[0]);
		pm->Free(pidl[1]);
		pm->Release();

		pFolder->Release();
	}
	return hr;
}
Beispiel #30
0
BOOL BrowseForPath(char *pathToBrowse)
{
	LPMALLOC shMalloc;
	BOOL changed = false;
	LPITEMIDLIST idList;
	BROWSEINFO bi;

	//stupid shell
	if(SHGetMalloc( &shMalloc) != S_OK)
		return FALSE;

	ZeroMemory(&idList, sizeof(idList));
	ZeroMemory(&bi, sizeof(bi));

	char tmp[MAX_PATH];
	strncpy(tmp, pathToBrowse, MAX_PATH);

	bi.hwndOwner = MainWindow->getHWnd();
	bi.lpszTitle = "Choose a Folder";
	bi.ulFlags = BIF_NONEWFOLDERBUTTON;

	/*wanted to add a callback function for the folder initialization but it crashes everytime i do
	bi.lpfn = (BFFCALLBACK)InitialFolder;
	bi.lParam = (LPARAM)pathToBrowse;
	*/

	if( (idList = SHBrowseForFolder(&bi)) )
	{
		changed = true;
		SHGetPathFromIDList(idList, pathToBrowse);
//		shMalloc->Free(&idList);
	}

	return changed;
}