Browse for Folder

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Browse for Folder

Post by mol »

Hi!
I need function BrowseForFolder.
Grigori Filatov posted such a sample a lot of time ago.
But, I want to ask if can we improve it, by adding possibilities to create new folder.

It's strange, but, if I put this code in another module, searching always start fom desktop and header is taken default.
It looks like a problem with passing parameters to this function
gfilatov wrote:
esgici wrote:Hi all

Does anyone know a way to adding a second parameter for <Initial Folder> to GetFolder() function ?

Or a new function with this ability ?
Hi Esgici,

Please try the following simple sample: :arrow:

Code: Select all

#include "minigui.ch"

Procedure Main()

	DEFINE WINDOW Form_1 ;
		AT 0,0 WIDTH 200 HEIGHT 150 ;
		MAIN ;
		TITLE "GetFolder Sample" ;
		NOSIZE

		DEFINE MAIN MENU
			DEFINE POPUP 'Test'
				MENUITEM 'BrowseForFolder()' ACTION MsgInfo(BrowseForFolder('Select Folder', GetCurrentFolder()),"Result")
				MENUITEM 'Exit' ACTION Form_1.Release
			END POPUP
		END MENU


	END WINDOW

	Form_1.Center
	Form_1.Activate

Return

*-----------------------------------------------------------------------------*
Static Function BrowseForFolder( cTitle, cInitPath )
*-----------------------------------------------------------------------------*
Return HMG_BrowseForFolder( NIL, cTitle, NIL, NIL, cInitPath )

*------------------------------------------------------------------------------*
* Low Level C Routines
*------------------------------------------------------------------------------*

#pragma BEGINDUMP

#include <windows.h>
#include "hbapi.h"

#include <commdlg.h>
#include <shlobj.h>
#include <commctrl.h>

int CALLBACK BrowseCallbackProc ( HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData )
{
   TCHAR szPath[ MAX_PATH ];

   switch( uMsg )
   {
   case BFFM_INITIALIZED:  if( lpData )
         SendMessage( hWnd, BFFM_SETSELECTION, TRUE, lpData );
      break;
   case BFFM_SELCHANGED:   SHGetPathFromIDList( ( LPITEMIDLIST ) lParam, szPath ); SendMessage( hWnd, BFFM_SETSTATUSTEXT, 0, ( LPARAM ) szPath );
   }

   return 0;
}

HB_FUNC( HMG_BROWSEFORFOLDER )  // Syntax: HMG_BROWSEFORFOLDER([<hWnd>],[<cTitle>],[<nFlags>],[<nFolderType>],[<cInitPath>])
{
   HWND hWnd = HB_ISNIL( 1 ) ? GetActiveWindow() : ( HWND ) hb_parnl( 1 );
   BROWSEINFO BrowseInfo;
   char *lpBuffer = ( char * ) hb_xgrab( MAX_PATH + 1 );
   LPITEMIDLIST pidlBrowse;

   SHGetSpecialFolderLocation( hWnd, HB_ISNIL(4) ? CSIDL_DRIVES : hb_parni(4), &pidlBrowse );

   BrowseInfo.hwndOwner = hWnd;
   BrowseInfo.pidlRoot = pidlBrowse;
   BrowseInfo.pszDisplayName = lpBuffer;
   BrowseInfo.lpszTitle = HB_ISNIL( 2 ) ? "Select a Folder" : hb_parc( 2 );
   BrowseInfo.ulFlags = HB_ISCHAR( 5 ) ? BIF_STATUSTEXT : hb_parni( 3 );
   BrowseInfo.lpfn = HB_ISCHAR( 5 ) ? BrowseCallbackProc : NULL;
   BrowseInfo.lParam = HB_ISCHAR( 5 ) ? ( LPARAM ) ( char * ) hb_parc( 5 ) : 0;
   BrowseInfo.iImage = 0;

   pidlBrowse = SHBrowseForFolder( &BrowseInfo );

   if( pidlBrowse )
   {
      SHGetPathFromIDList( pidlBrowse, lpBuffer );
      hb_retc( lpBuffer );
   }
   else
      hb_retc( "" );

   hb_xfree( lpBuffer );
}

#pragma ENDDUMP
Hope that useful :idea:
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Browse for Folder

Post by Pablo César »

Hi Marek,

I do not know if you have already solved about "Make New Folder" option in hb_BrowseForFolder.

Image

But it is very simple. According new source/sample of C:\MiniGUI\SAMPLES\Advanced\BrowseForFolder\demo.prg you can see this "Make New Folder" option can be applied to the nflag parameter adding BIF_NEWDIALOGSTYLE

See syntax with the right calling function:

Code: Select all

hb_BrowseForFolder( NIL, ;
                    BIF_EDITBOX + BIF_VALIDATE + BIF_NEWDIALOGSTYLE, ;
                    "Please select a location to store data files", ;
                    CurDrive() + ":\" + CurDir() )

hb_BrowseForFolder( NIL, cTitle, nflag, nfolder, cInitPath, lCenter )
I hope I have cleared your doubt but it was clear I can post an example.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Browse for Folder

Post by srvet_claudio »

Pablo César wrote:Hi Marek,

I do not know if you have already solved about "Make New Folder" option in hb_BrowseForFolder.


But it is very simple. According new source/sample of C:\MiniGUI\SAMPLES\Advanced\BrowseForFolder\demo.prg you can see this "Make New Folder" option can be applied to the nflag parameter adding BIF_NEWDIALOGSTYLE

See syntax with the right calling function:

Code: Select all

hb_BrowseForFolder( NIL, ;
                    BIF_EDITBOX + BIF_VALIDATE + BIF_NEWDIALOGSTYLE, ;
                    "Please select a location to store data files", ;
                    CurDrive() + ":\" + CurDir() )

hb_BrowseForFolder( NIL, cTitle, nflag, nfolder, cInitPath, lCenter )
I hope I have cleared your doubt but it was clear I can post an example.

See doc, is more easy:

Code: Select all

 GetFolder ( [<cTitle>] , [<cInitPath>], [<cInvalidDataMsg>], [<lNewFolderButton>] , [<lIncludeFiles>] , [<nCSIDL_FolderType>] , [<nBIF_Flags>] )--> cSelectedFolderName
 

-    nCSIDL_FolderType (constants defined in i_misc.ch): CSIDL (Constant Special Item ID List) values provide a unique system-independent way to identify special folders used frequently by applications, but which may not have the same name or location on any given system (for default CSIDL_DRIVES).
 
-    nBIF_Flags (constants defined in i_misc.ch):
     o    BIF_EDITBOX(*): Include an edit control in the browse dialog box that allows the user to type the name of an item.
     o    BIF_VALIDATE(*): If the user types an invalid name into the edit box, the browse dialog box calls the application's BrowseCallbackProc with the BFFM_VALIDATEFAILED message ( ignored if BIF_EDITBOX is not specified)
     o    BIF_NEWDIALOGSTYLE(*): Use the new user interface. Setting this flag provides the user with a larger dialog box that can be resized. The dialog box has several new capabilities, including: drag-and-drop capability within the dialog box,reordering, shortcut menus, new folders, delete, and other shortcut menu commands.
     o    BIF_USENEWUI(*): equivalent to BIF_EDITBOX + BIF_NEWDIALOGSTYLE.
(*) set for default.
 
     o    BIF_RETURNONLYFSDIRS: Only return file system directories.
     o    BIF_DONTGOBELOWDOMAIN: Do not include network folders below the domain level in the dialog box's tree view control.
     o    BIF_STATUSTEXT: Include a status area in the dialog box ( not supported when BIF_NEWDIALOGSTYLE )
     o    BIF_RETURNFSANCESTORS: Only return file system ancestors. An ancestor is a subfolder that is beneath the root folder in the namespace hierarchy.
     o    BIF_BROWSEINCLUDEURLS: The browse dialog box can display URLs. The BIF_USENEWUI and BIF_BROWSEINCLUDEFILES flags must also be set.
     o    BIF_UAHINT: When combined with BIF_NEWDIALOGSTYLE, adds a usage hint to the dialog box, in place of the edit box (BIF_EDITBOX overrides this flag)
     o    BIF_NONEWFOLDERBUTTON: Do not include the New Folder button in the browse dialog box.
     o    BIF_NOTRANSLATETARGETS: When the selected item is a shortcut, return the PIDL of the shortcut itself rather than its target.
     o    BIF_BROWSEFORCOMPUTER: Only return computers
     o    BIF_BROWSEFORPRINTER: Only allow the selection of printers. In Windows XP and later systems, the best practice is to use a Windows XP-style dialog, setting the root of the dialog to the Printers and Faxes folder (CSIDL_PRINTERS).
     o    BIF_BROWSEINCLUDEFILES: The browse dialog box displays files as well as folders.
     o    BIF_SHAREABLE: The browse dialog box can display sharable resources on remote systems. The BIF_NEWDIALOGSTYLE flag must also be set.
     o    BIF_BROWSEFILEJUNCTIONS: Windows 7 and later. Allow folder junctions such as a library or a compressed file with a .zip file name extension to be browsed.

Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Browse for Folder

Post by Pablo César »

Thanks Claudio for your additional clarification, very rich doc. This was announced at this topic (see at "Improvement in GetFolder()")

So many options, would be very usefull to elaborate vary examples of all of these ressources.

At least for me, many others ressources was not tested yet... thank you again Claudio !

Feliz año nuevo !
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Browse for Folder

Post by srvet_claudio »

Pablo César wrote:Thanks Claudio for your additional clarification, very rich doc. This was announced at this topic (see at "Improvement in GetFolder()")

So many options, would be very usefull to elaborate vary examples of all of these ressources.

At least for me, many others ressources was not tested yet... thank you again Claudio !

Feliz año nuevo !
Feliz año nuevo para vos también!!!
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
karweru
Posts: 220
Joined: Fri Aug 01, 2008 1:51 pm
DBs Used: DBF,mysql,mariadb,postgresql,sqlite,odbc
Contact:

Re: Browse for Folder

Post by karweru »

When i issue getFolder("select report folder",GetMyDocumentsFolder()), the folder select dialogue ignores the second parameter.
Attachments
Screenshot_1.png
Screenshot_1.png (18.79 KiB) Viewed 4038 times
Kind regards,
Gilbert.
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Browse for Folder

Post by edk »

Maybe this topic http://hmgforum.com/viewtopic.php?p=54999#p54999 will be helpful?
User avatar
karweru
Posts: 220
Joined: Fri Aug 01, 2008 1:51 pm
DBs Used: DBF,mysql,mariadb,postgresql,sqlite,odbc
Contact:

Re: Browse for Folder

Post by karweru »

Thanks,

I got the behavior in wanted using putfile(<default_file_name>,GetMyDocumentsFolder())
Kind regards,
Gilbert.
Post Reply