Unicode TopenFolder Dioalog ?
-
Hallo,
sacht ma ich suche sowas wie ein TOpenFolderDialog der Unicode unterstützt.
Habe leider nur sowas hier funktioniert auch astrein.
Einen richtigen Umbau auf Unicode bekomm ich dennoch nicht hin da ich es nicht schaffe den zuletzt ausgewählten Ordner selectiert anziegen zu lassen im Dialog.Vielleicht kann ja einer von Euch da was machen, ich bin einfach zu blöde dazu.
Hier mal die ANSI Version von dem ganzen Teil.char FolderName[MAX_PATH + 1] = "\0"; __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { strcpy(FolderName, "D:\\Windows\\Temp"); } int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { switch (uMsg) { case BFFM_INITIALIZED : if(lpData) SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData); break; case BFFM_SELCHANGED : SHGetPathFromIDList(PItemIDList(lParam), FolderName); //TRACE1(_T("%d\n"), BFFM_SELCHANGED); break; case BFFM_VALIDATEFAILED : break; default: break; } return 0; } bool ChooseFolder(char* FolderName) { bool bReturn; char dirName[MAX_PATH + 1] = {0}; strcpy( dirName, FolderName ); BROWSEINFO brInfo; brInfo.hwndOwner = Form1->Handle; brInfo.pidlRoot = NULL; brInfo.pszDisplayName = dirName; brInfo.lpszTitle = _T("Ordner auswählen:"); brInfo.ulFlags = 0; brInfo.lpfn = BrowseCallbackProc; brInfo.lParam = (long) dirName; //Folder_name for initial_selection brInfo.iImage = 4; LPITEMIDLIST pidl; if(pidl=SHBrowseForFolder(&brInfo)) { // Item was selected && OK was selected if( SHGetPathFromIDList(pidl, dirName) ) { // got Full_Path for selected dirName FolderName = dirName; bReturn = true; } else { bReturn = false; } } else { // CANCEL was selected // FolderName is undefined bReturn = false; } // Allocate a pointer to an IMalloc interface LPMALLOC pMalloc; // Get the address of our task allocator's IMalloc interface SHGetMalloc(&pMalloc); // Free the item ID list allocated by SHGetSpecialFolderLocation pMalloc->Free(pidl); // Free our task allocator pMalloc->Release(); return true; } void __fastcall TForm1::Button2Click(TObject *Sender) { ChooseFolder(FolderName); }
-
Hi,
naja ich habs nun doch noch hinbekommen, fragt mich nicht warum ich mich so blöde angestellt habe die ganzen Tage.
Hier jetzt der --- UNICODE OPENFOLDER DIALOG ---
//--------------------------------------------------------------------------- #define NO_WIN32_LEAN_AND_MEAN #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; wchar_t FolderName[MAX_PATH + 1] = L"\0"; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { wcscpy(FolderName, L"C:\\"); } //--------------------------------------------------------------------------- int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { switch (uMsg) { case BFFM_INITIALIZED : if(lpData) SendMessage(hwnd, BFFM_SETSELECTIONW, TRUE, lpData); break; case BFFM_SELCHANGED : SHGetPathFromIDListW(PItemIDList(lParam), FolderName); //kopiert von LParam nach Foldername break; case BFFM_VALIDATEFAILED : break; default: break; } return 0; } bool ChooseFolder(wchar_t* FolderName) { bool bReturn; wchar_t dirName[MAX_PATH + 1] = {0}; wcscpy ( dirName, FolderName ); BROWSEINFOW brInfo; brInfo.hwndOwner = Form1->Handle; brInfo.pidlRoot = NULL; brInfo.pszDisplayName = dirName; brInfo.lpszTitle = L"Ordner auswählen:"; brInfo.ulFlags = 0; brInfo.lpfn = BrowseCallbackProc; brInfo.lParam = (long) dirName; //Folder_name for initial_selection brInfo.iImage = 4; LPITEMIDLIST pidl; if(pidl=SHBrowseForFolderW(&brInfo)) { // Item was selected && OK was selected if( SHGetPathFromIDListW(pidl, dirName) ) { //MessageBoxW(Application->Handle, dirName, L"TestDialog", 0); // got Full_Path for selected dirName FolderName = dirName; bReturn = true; } else { bReturn = false; } } else { // CANCEL was selected // FolderName is undefined bReturn = false; } // Allocate a pointer to an IMalloc interface LPMALLOC pMalloc; // Get the address of our task allocator's IMalloc interface SHGetMalloc(&pMalloc); // Free the item ID list allocated by SHGetSpecialFolderLocation pMalloc->Free(pidl); // Free our task allocator pMalloc->Release(); return bReturn; } void __fastcall TForm1::Button2Click(TObject *Sender) { ChooseFolder(FolderName); } //---------------------------------------------------------------------------