FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Select a folder without using the cGetDir function RESOLVED
Posts: 99
Joined: Thu Jul 12, 2007 02:02 PM
Select a folder without using the cGetDir function RESOLVED
Posted: Wed Nov 27, 2024 03:19 PM
Hi all,

I would like to select a folder using a form similar to that for selecting a file,
not like the one used by the cGetDir function.

A form like the example below



Can someone help me ?

Thanks in advance
Massimo
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Select a folder without using the cGetDir function
Posted: Wed Nov 27, 2024 04:00 PM
In this case it is possible to select a folder or file
Code (fw): Select all Collapse
  
#define BIF_RETURNONLYFSDIRS 0x0001
#define BIF_DONTGOBELOWDOMAIN 0x0002
#define BIF_STATUSTEXT 0x0004
#define BIF_RETURNFSANCESTORS 0x0008
#define BIF_EDITBOX 0x0010
#define BIF_VALIDATE 0x0020
#define BIF_NEWDIALOGSTYLE 0x0040
#define BIF_USENEWUI (BIF_NEWDIALOGSTYLE|BIF_EDITBOX)
#define BIF_BROWSEINCLUDEURLS 0x0080
#define BIF_BROWSEFORCOMPUTER 0x1000
#define BIF_BROWSEFORPRINTER 0x2000
#define BIF_BROWSEINCLUDEFILES 0x4000
#define BIF_SHAREABLE 0x8000

itm:=cGetDir(Title,,,, BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN + BIF_USENEWUI + ;
        BIF_BROWSEINCLUDEFILES + BIF_NONEWFOLDERBUTTON, .T. )
Posts: 99
Joined: Thu Jul 12, 2007 02:02 PM
Re: Select a folder without using the cGetDir function
Posted: Wed Nov 27, 2024 04:21 PM

Thank you Natter,

but I didn't want to use the cGetDir function,

searching online I found that you could use the IFileDialog interface

(from Windows Vista)

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Select a folder without using the cGetDir function
Posted: Wed Nov 27, 2024 04:46 PM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Select a folder without using the cGetDir function
Posted: Wed Nov 27, 2024 04:50 PM
Sorry, MaxP ! I could only achieve this design for the “Save As” function :(
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Select a folder without using the cGetDir function
Posted: Thu Nov 28, 2024 05:51 AM
Working fine:
Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()

    MsgInfo( GetFolder() )

return nil

#pragma BEGINDUMP

#include <windows.h>
#include <shobjidl.h>
#include <stdio.h>
#include <hbapi.h>

LPSTR FW_WideToAnsi( LPWSTR pWide );

void GetFolder()
{
    HRESULT hr;
    IFileDialog *pFileDialog = NULL;

    // Initialize COM library
    hr = CoInitialize(NULL);
    if (SUCCEEDED(hr))
    {
        // Create the File Open Dialog object
        hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, &IID_IFileDialog, (void **)&pFileDialog);
        if (SUCCEEDED(hr))
        {
            // Set the dialog options to pick folders
            DWORD dwOptions;
            hr = pFileDialog->lpVtbl->GetOptions(pFileDialog, &dwOptions);
            if (SUCCEEDED(hr))
            {
                hr = pFileDialog->lpVtbl->SetOptions(pFileDialog, dwOptions | FOS_PICKFOLDERS);
                if (SUCCEEDED(hr))
                {
                    // Show the dialog
                    hr = pFileDialog->lpVtbl->Show(pFileDialog, NULL);
                    if (SUCCEEDED(hr))
                    {
                        // Retrieve the selected folder
                        IShellItem *pItem = NULL;
                        hr = pFileDialog->lpVtbl->GetResult(pFileDialog, &pItem);
                        if (SUCCEEDED(hr))
                        {
                            PWSTR pszFolderPath = NULL;
                            hr = pItem->lpVtbl->GetDisplayName(pItem, SIGDN_FILESYSPATH, &pszFolderPath);
                            if (SUCCEEDED(hr))
                            {
                                hb_retc( FW_WideToAnsi( pszFolderPath ) );
                                CoTaskMemFree(pszFolderPath);
                            }
                            pItem->lpVtbl->Release(pItem);
                        }
                    }
                }
            }
            pFileDialog->lpVtbl->Release(pFileDialog);
        }
        else
            hb_retc( "" );
    }
    CoUninitialize();
}

HB_FUNC( GETFOLDER )
{
   GetFolder(); 
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 99
Joined: Thu Jul 12, 2007 02:02 PM
Re: Select a folder without using the cGetDir function
Posted: Thu Nov 28, 2024 10:00 AM
Thank you very much Antonio,

this is exactly what I was looking for,
you are always our boss

Good day :)

Continue the discussion