Dialog mit Neuen Ordner erstellen



  • Hallo,

    wollte nur mal ne einfachere Lösung presentieren als in der FAQ:

    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #pragma hdrstop
    
    #include "Unit1.h"
    #include <shlobj.h>
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //------------------------------------------------------------------------------
    // Windows-Verzeichnisauswahl-Dialog anzeigen 
    AnsiString SelectFolderDialog(HWND handle, AnsiString titel, AnsiString pfad) 
    {
    LPITEMIDLIST pidl;
    BROWSEINFO info;
    char szDir[MAX_PATH];
    char szDisplayName[MAX_PATH];
    LPMALLOC pShellMalloc;
    
    if (SHGetMalloc(&pShellMalloc) == NO_ERROR)
    {
    memset(&info, 0x00, sizeof(info));
    
    info.hwndOwner = handle;
    info.pidlRoot = 0;
    info.pszDisplayName = szDisplayName;
    info.lpszTitle = titel.c_str();
    info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE ; 
    info.lParam = (int) pfad.c_str();
    info.lpfn = 0;
    
    //Verzeichnis anzeigen
    pidl = SHBrowseForFolder(&info);
    
    // Id in Pfad umwandeln
    if (pidl)
    SHGetPathFromIDList(pidl, szDir);
    
    // aufräumen
    pShellMalloc->Free(pidl);
    pShellMalloc->Release();
    return (AnsiString)szDir;
    }
    }
    //------------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    AnsiString folder = SelectFolderDialog(Form1->Handle,
    "Bitte wählen sie den Speicherort",
    "");
    
    }
    //---------------------------------------------------------------------------
    

    Viel Spaß damit

    Gruß Daniel


Anmelden zum Antworten