Page 1 of 1

Select a folder without using the cGetDir function RESOLVED

Posted: Wed Nov 27, 2024 3:19 pm
by MaxP
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

Image

Can someone help me ?

Thanks in advance
Massimo

Re: Select a folder without using the cGetDir function

Posted: Wed Nov 27, 2024 4:00 pm
by Natter
In this case it is possible to select a folder or file

Code: Select all | Expand

  
#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. )

Re: Select a folder without using the cGetDir function

Posted: Wed Nov 27, 2024 4:21 pm
by MaxP
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)

Re: Select a folder without using the cGetDir function

Posted: Wed Nov 27, 2024 4:46 pm
by karinha

Code: Select all | Expand

cGetFile()
cGetDir()
cGetDir32()
 
https://forums.fivetechsupport.com/view ... 9b#p216104

Regards, saludos.

Re: Select a folder without using the cGetDir function

Posted: Wed Nov 27, 2024 4:50 pm
by Natter
Sorry, MaxP ! I could only achieve this design for the “Save As” function :(

Re: Select a folder without using the cGetDir function

Posted: Thu Nov 28, 2024 5:51 am
by Antonio Linares
Working fine:

Code: Select all | Expand

#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

Re: Select a folder without using the cGetDir function

Posted: Thu Nov 28, 2024 10:00 am
by MaxP
Thank you very much Antonio,

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

Good day :)