Select a folder without using the cGetDir function RESOLVED

Select a folder without using the cGetDir function RESOLVED

Postby MaxP » Wed Nov 27, 2024 3: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

Image

Can someone help me ?

Thanks in advance
Massimo
Last edited by MaxP on Thu Nov 28, 2024 10:00 am, edited 1 time in total.
User avatar
MaxP
 
Posts: 88
Joined: Thu Jul 12, 2007 2:02 pm

Re: Select a folder without using the cGetDir function

Postby Natter » Wed Nov 27, 2024 4:00 pm

In this case it is possible to select a folder or file
Code: Select all  Expand view  RUN
 
#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. )
Natter
 
Posts: 1226
Joined: Mon May 14, 2007 9:49 am

Re: Select a folder without using the cGetDir function

Postby MaxP » Wed Nov 27, 2024 4: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)
User avatar
MaxP
 
Posts: 88
Joined: Thu Jul 12, 2007 2:02 pm

Re: Select a folder without using the cGetDir function

Postby karinha » Wed Nov 27, 2024 4:46 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7872
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Select a folder without using the cGetDir function

Postby Natter » Wed Nov 27, 2024 4:50 pm

Sorry, MaxP ! I could only achieve this design for the “Save As” function :(
Natter
 
Posts: 1226
Joined: Mon May 14, 2007 9:49 am

Re: Select a folder without using the cGetDir function

Postby Antonio Linares » Thu Nov 28, 2024 5:51 am

Working fine:

Code: Select all  Expand view  RUN
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Select a folder without using the cGetDir function

Postby MaxP » 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 :)
User avatar
MaxP
 
Posts: 88
Joined: Thu Jul 12, 2007 2:02 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 12 guests