CFileDialog NUR mit pfad?
-
Na am besten wäre beides!
Aber ich hab GetFolderPath() shon gefunden....fehlr nur noch das ich nur den Pfad wählen kann
-
Boah, so ohne Suche is das Finden echt mühselig.

http://www.c-plusplus.net/forum/viewtopic-var-t-is-39127.html :xmas1:
-
ha die suche bemüht, aber mit dem flaschen stichwort....*CFileDialog* und *CFile*...
Aber Danke trotzdem

-
Uruk-h4j schrieb:
ha die suche bemüht, aber mit dem flaschen stichwort....*CFileDialog* und *CFile*...
Aber Danke trotzdem

Die Suche ist kaputt. Deswegen brauchte ich ja auch so lange, bis ich den Link endlich hatte.
Es war ausnahmsweise keine Anspielung, dass du selber suchen solltest.
-
hmmm...hab mal frecherweise die .cpp und .h kopiert und komischerweise hab ich so ca. 34 Fehler. Ich hab nichts verändert oder sonst was gemacht.
Die sind alle in dem Bereich:
int __stdcall CDirDialog::BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { CDirDialog* pDirDialogObj = (CDirDialog*)lpData; if (uMsg == BFFM_INITIALIZED ) { if( ! pDirDialogObj->m_strSelDir.IsEmpty() ) ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)(LPCTSTR)(pDirDialogObj->m_strSelDir)); if( ! pDirDialogObj->m_strWindowTitle.IsEmpty() ) ::SetWindowText(hwnd, (LPCTSTR) pDirDialogObj->m_strWindowTitle); } else if( uMsg == BFFM_SELCHANGED ) { LPITEMIDLIST pidl = (LPITEMIDLIST) lParam; char selection[MAX_PATH]; if( ! ::SHGetPathFromIDList(pidl, selection) ) selection[0] = '\0'; CString csStatusText; BOOL bOk = pDirDialogObj->SelChanged(selection, csStatusText); if( pDirDialogObj->m_bStatus ) ::SendMessage(hwnd, BFFM_SETSTATUSTEXT , 0, (LPARAM)(LPCSTR)csStatusText); ::SendMessage(hwnd, BFFM_ENABLEOK, 0, bOk); } return 0;Irgendwas mit der Variable "gt" passt nicht.
"warning C4067: Unerwartete Token nach Präprozessordirektive - Zeilenvorschub erwartet."#if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000Bin ich zu doof zumm STG-C STRG-V ?
-
Uruk-h4j schrieb:
Irgendwas mit der Variable "gt" passt nicht.
"warning C4067: Unerwartete Token nach Präprozessordirektive - Zeilenvorschub erwartet."#if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000Bin ich zu doof zumm STG-C STRG-V ?
Das war keine Variable, das war HTML.
Da scheint mal was die Beiträge teilweise zerschossen zu haben.Guck nochmal in die FAQ, ich habs repariert.

-
Jo DER Fehler ist weg, aber ein problem ist noch:
Dadurch, dass da nun keine var gt mehr ist stimmt das hier irgendwe net mehr so:
int __stdcall CDirDialog::BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { CDirDialog* pDirDialogObj = (CDirDialog*)lpData; if (uMsg == BFFM_INITIALIZED ) { if( ! pDirDialogObj->m_strSelDir.IsEmpty() ) ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)(LPCTSTR)(pDirDialogObj->m_strSelDir)); if( ! pDirDialogObj->m_strWindowTitle.IsEmpty() ) ::SetWindowText(hwnd, (LPCTSTR) pDirDialogObj->m_strWindowTitle); } else if( uMsg == BFFM_SELCHANGED ) { LPITEMIDLIST pidl = (LPITEMIDLIST) lParam; char selection[MAX_PATH]; if( ! ::SHGetPathFromIDList(pidl, selection) ) selection[0] = '\0'; CString csStatusText; BOOL bOk = pDirDialogObj->SelChanged(selection, csStatusText); if( pDirDialogObj->m_bStatus ) ::SendMessage(hwnd, BFFM_SETSTATUSTEXT , 0, (LPARAM)(LPCSTR)csStatusText); ::SendMessage(hwnd, BFFM_ENABLEOK, 0, bOk); } return 0; }Wel da wir überall auf gt zugegriffen. Gehört das auch noch zu HTML oder muss ich gt neu zuweisen?
-
so hab alle "-gt" entfernt und alles angepasst. Läuft auch alles wie es scheint. Vielleicht sollte man das mal im FAQ ändern !?
Header:
#if !defined(AFX_DIRDIALOG_H__62FFAC92_1DEE_11D1_B87A_0060979CDF6D__INCLUDED_) #define AFX_DIRDIALOG_H__62FFAC92_1DEE_11D1_B87A_0060979CDF6D__INCLUDED_ #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 class CDirDialog { public: CDirDialog(); virtual ~CDirDialog(); BOOL DoBrowse(CWnd *pwndParent = NULL); CString m_strWindowTitle; CString m_strPath; CString m_strInitDir; CString m_strSelDir; CString m_strTitle; int m_iImageIndex; BOOL m_bStatus; private: virtual BOOL SelChanged(LPCSTR lpcsSelection, CString &csStatusText) { return TRUE; }; static int __stdcall CDirDialog::BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData); }; #endif // !defined(AFX_DIRDIALOG_H__62FFAC92_1DEE_11D1_B87A_0060979CDF6D__INCLUDED_)CPP:
#include "stdafx.h" #include "DirDialog.h" #include "shlobj.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif int __stdcall CDirDialog::BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { CDirDialog* pDirDialogObj = (CDirDialog*)lpData; if (uMsg == BFFM_INITIALIZED ) { if( !pDirDialogObj->m_strSelDir == NULL ) ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE,(LPARAM)(LPCTSTR)(pDirDialogObj->m_strSelDir)); if( !pDirDialogObj->m_strWindowTitle == NULL ) ::SetWindowText(hwnd, pDirDialogObj->m_strWindowTitle); } else if( uMsg == BFFM_SELCHANGED ) { LPITEMIDLIST pidl = (LPITEMIDLIST) lParam; char selection[MAX_PATH]; if( ! ::SHGetPathFromIDList(pidl, selection) ) selection[0] = '\0'; CString csStatusText; BOOL bOk = pDirDialogObj->SelChanged(selection, csStatusText); if( pDirDialogObj->m_bStatus ) ::SendMessage(hwnd, BFFM_SETSTATUSTEXT , 0, (LPARAM)(LPCSTR)csStatusText); ::SendMessage(hwnd, BFFM_ENABLEOK, 0, bOk); } return 0; } CDirDialog::CDirDialog() { m_bStatus = FALSE; } CDirDialog::~CDirDialog() { } BOOL CDirDialog::DoBrowse(CWnd *pwndParent) { if( ! m_strSelDir.IsEmpty() ) { m_strSelDir.TrimRight(); if( m_strSelDir.Right(1) == "\\" | m_strSelDir.Right(1) == "//" ) m_strSelDir = m_strSelDir.Left(m_strSelDir.GetLength() - 1); } LPMALLOC pMalloc; if (SHGetMalloc (&pMalloc)!= NOERROR) return FALSE; BROWSEINFO bInfo; LPITEMIDLIST pidl; ZeroMemory ( (PVOID) &bInfo,sizeof (BROWSEINFO)); if (!m_strInitDir.IsEmpty ()) { OLECHAR olePath[MAX_PATH]; ULONG chEaten; ULONG dwAttributes; HRESULT hr; LPSHELLFOLDER pDesktopFolder; // // Get a pointer to the Desktop's IShellFolder interface. // if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder))) { // // IShellFolder::ParseDisplayName requires the file name be in Unicode. // MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strInitDir.GetBuffer(MAX_PATH), -1, olePath, MAX_PATH); m_strInitDir.ReleaseBuffer (-1); // // Convert the path to an ITEMIDLIST. // hr = pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, &chEaten, &pidl, &dwAttributes); if (FAILED(hr)) { pMalloc->Free (pidl); pMalloc->Release (); return FALSE; } bInfo.pidlRoot = pidl; } } bInfo.hwndOwner = pwndParent == NULL ? NULL : pwndParent->GetSafeHwnd(); bInfo.pszDisplayName = m_strPath.GetBuffer (MAX_PATH); bInfo.lpszTitle = (m_strTitle.IsEmpty()) ? "Open" : m_strTitle; bInfo.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS | (m_bStatus ? BIF_STATUSTEXT : 0); bInfo.lpfn = BrowseCtrlCallback; // address of callback function bInfo.lParam = (LPARAM)this; // pass address of object to callback function if ((pidl = ::SHBrowseForFolder(&bInfo)) == NULL) { return FALSE; } m_strPath.ReleaseBuffer(); m_iImageIndex = bInfo.iImage; if (::SHGetPathFromIDList(pidl, m_strPath.GetBuffer(MAX_PATH)) == FALSE) { pMalloc->Free(pidl); pMalloc->Release(); return FALSE; } m_strPath.ReleaseBuffer(); pMalloc->Free(pidl); pMalloc->Release(); return TRUE; }Mich wunderts aber, dass so eine Klasse nicht in MFC integriert ist...
-
Nun eine Klasse gibts dafür nicht aber es gibt doch SHBrowseForFolder(..)

Bsp.:
CoInitialize(NULL); //funktioniert auch ohne diesen Aufruf BROWSEINFO bi; memset( &bi, 0, sizeof( BROWSEINFO ) ); bi.hwndOwner = AfxGetMainWnd()->GetSafeHwnd(); bi.lpszTitle = "Bitte wählen Sie ein Verzeichnis..."; bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; ITEMIDLIST* pList = SHBrowseForFolder( &bi ); if( pList ) { char szFolder[MAX_PATH+1]=""; if( SHGetPathFromIDList( pList, szFolder) ) { m_sPath = szFolder; this->SetDlgItemTextA(IDC_STATIC, m_sPath ); } LPMALLOC pMalloc=NULL; if( S_OK == SHGetMalloc( &pMalloc ) ) { pMalloc->Free( pList ); pMalloc->Release(); } } CoUninitialize();
-
Ah...das ist natürlich kürzer ^^
Und auch das was ich suche. Hat a auch den selben effekt, wie die Klasse auf der ersten Seite. THX!