Select Folder Dialog

Posted By: oliver2s

Select Folder Dialog - 01/16/14 12:53

This functions opens a Windows Dialog in which you can select a folder and get the full path as string.

For more info:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb773205(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762115(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762194(v=vs.85).aspx

Code:
typedef struct _BROWSEINFO
{
	long		hwndOwner;
	char*		pidlRoot;
	char*		pszDisplayName;
	char*		lpszTitle;
	long		ulFlags;
	long		lpfn;
	long		lParam;
	int		iImage;
}BROWSEINFO;

DWORD WINAPI SHBrowseForFolder(DWORD);
DWORD WINAPI SHGetPathFromIDList(long,long);
API(SHBrowseForFolder,shell32)
API(SHGetPathFromIDList,shell32)
#define PRAGMA_API SHBrowseForFolder;shell32!SHBrowseForFolderA
#define PRAGMA_API SHGetPathFromIDList;shell32!SHGetPathFromIDListA

#define BIF_RETURNONLYFSDIRS 0x00000001
#define BIF_DONTGOBELOWDOMAIN 0x00000002
#define BIF_STATUSTEXT 0x00000004
#define BIF_RETURNFSANCESTORS 0x00000008
#define BIF_EDITBOX 0x00000010
#define BIF_VALIDATE 0x00000020
#define BIF_NEWDIALOGSTYLE 0x00000040
#define BIF_BROWSEINCLUDEURLS 0x00000080
#define BIF_UAHINT 0x00000100
#define BIF_NONEWFOLDERBUTTON 0x00000200
#define BIF_NOTRANSLATETARGETS 0x00000400
#define BIF_BROWSEFORCOMPUTER 0x00001000
#define BIF_BROWSEFORPRINTER 0x00002000
#define BIF_BROWSEINCLUDEFILES 0x00004000
#define BIF_SHAREABLE 0x00008000
#define BIF_BROWSEFILEJUNCTIONS 0x00010000

function folder_dialog(STRING* dir)
{
	STRING* DirName = str_create("#255"); *DirName.chars=0;
	
	BROWSEINFO FOdlg;   memset(FOdlg, 0, sizeof(BROWSEINFO));   
	FOdlg.pszDisplayName    = DirName.chars;
	FOdlg.ulFlags				= NULL;
	
	long lpItem = SHBrowseForFolder(&FOdlg);
	
	if(lpItem==0)
	{
		str_remove(DirName);
		return(0);
	}
	else
	{
		SHGetPathFromIDList(lpItem, DirName.chars);
		str_cpy(dir, DirName);
		str_remove(DirName);
		return(1);
	}
}



How to use:
Code:
STRING* str_folder="";
folder_dialog(str_folder);

Posted By: gri

Re: Select Folder Dialog - 01/17/14 07:30

nice, thank you.
Posted By: PrenceOfDarkness

Re: Select Folder Dialog - 03/19/14 20:13

Man... How do you know how to do stuff like that? I find using anything windows related so over welming. Is there a programming magizine online out there
Similar to aum??
Posted By: Ch40zzC0d3r

Re: Select Folder Dialog - 03/19/14 21:07

Well theres something called google.
Second result on google will get you this code, and implementing code form google is not a very hard task XD
Ofcourse nobody knows ALL of the windows stuff. Just use google, it'll be fine tongue
Posted By: oliver2s

Re: Select Folder Dialog - 03/20/14 08:28

Originally Posted By: Ch40zzC0d3r
Well theres something called google.
Second result on google will get you this code, and implementing code form google is not a very hard task XD
Ofcourse nobody knows ALL of the windows stuff. Just use google, it'll be fine tongue


Yes, signed. Google + Windows API online manual = that's all wink
Posted By: sivan

Re: Select Folder Dialog - 03/20/14 08:35

+ many years programming experience grin
Posted By: rojart

Re: Select Folder Dialog - 03/20/14 15:49

Really helpful, thanks.
© 2024 lite-C Forums