Browse for Folder
Posted: Fri Nov 16, 2012 8:38 am
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
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:Hi Esgici,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 ?
Please try the following simple sample:
Hope that usefulCode: 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