Thread: User Choosing Directory Dialog Box

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    3

    Question User Choosing Directory Dialog Box

    I need some help on this. I need my user to be able to navigate the directorys and be able to choose one to select. Basically, I want to use the built in file picker for windows, but want to choose a folder/directory instead of a file. If there is a built in call for something like this I would love to use it. All I need the function to return is the path for the directory. I have all the rest of my code built, but I don't want the poor user to have to type in the directory. If i have to I could write a whole new function to do this, but it would probably be 10 times larger than the rest of the program.

    Any help would be appreciated.

    Thanks,

    Matt

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You can use SHBrowseForFolder(). Try something like this -

    Code:
    	CoInitialize(0);
    
    	char szDirectory[1024];
    	HRESULT hr;
    	BROWSEINFO browseInfo;
    	LPITEMIDLIST lpItemList=0;
    
    	LPMALLOC lpM;
    	hr = SHGetMalloc (&lpM) ;
    	if (FAILED(hr) ) return 0;
    
    	ZeroMemory ( (PVOID) &browseInfo,sizeof (BROWSEINFO));
      
      	browseInfo.pidlRoot = 0;
    	browseInfo.hwndOwner = NULL;
    	browseInfo.pszDisplayName = szDirectory;
    	browseInfo.lpszTitle = "Open Folder ";
    	browseInfo.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS;
    	browseInfo.lParam = 0;
    
    	if ((lpItemList = SHBrowseForFolder(&browseInfo)) == NULL)
    	{
    		return 0;
    	}
    
    	SHGetPathFromIDList(lpItemList,szDirectory); 
    
    
    	MessageBox(0,szDirectory,"Path",0);
    
    	lpM->Free(lpItemList);
    	lpM->Release();

  3. #3
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    ...also, include shlobj.h.

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    3
    Thank you!!!!!!!!!! I never heard of the SHBrowseForFolder. Now I know, and knowing is half the battle. Now I just have to make my interface look prettier, and I am done. Thank you so much once again.

    Matt

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    THANK YOU FOR THE DIR BROWSER

    thanks, I had been looking for this for a little while now.

    zMan
    zMan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dialog box problem keeps haunting me
    By Bleech in forum Windows Programming
    Replies: 2
    Last Post: 08-23-2006, 01:12 AM
  2. Display Dialog Box Then Execute
    By stickman in forum C++ Programming
    Replies: 17
    Last Post: 05-10-2006, 11:02 AM
  3. Making dialog box the only window
    By PJYelton in forum Windows Programming
    Replies: 2
    Last Post: 09-06-2005, 12:02 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. User Input without Dialog box?
    By Isometric in forum Windows Programming
    Replies: 2
    Last Post: 11-22-2001, 02:27 AM