SHBrowseForFolder mit ulFlags BIF_NEWDIALOGSTYLE



  • hi,

    ich hab das problem das ich SHBrowseForFolder mit ulFlags BIF_NEWDIALOGSTYLE nicht zum laufen bekomme, egal ob mit jenem codeschnipsel oder dem der CDirDialog klasse die man hier im forum findet und auch sonst funktioniert.

    der kompilierer meldet immer nicht deklarierter bezeichner, in der MSDN hab ich auf der BROWSEINFO Structure Seite gelesen das man zuvor OleInitialize() oder CoInitialize() aufrufen muss. Trotzdem bekomme ich die meldung mit dem nicht deklariertem bezeichner .. die header datei (objbase.h) hab ich auch schon inkludiert und die lib (ole32.lib) in den linker der einstellungen eingetragen.

    hab ich irgendwas vergessen oder übersehen?

    mfg dennis



  • zeig mal bischen mehr Code ih hab es auch schon gemacht allerdings nicht mit dem genannten Flag! Aber was für Fehlermeldungen bekommst du? Geht nicht sagt nicht allzuviel aus!

    mfg



  • hi,

    der code ist fast identisch mit dem von der CDirDialog klasse die man hier im forum findet .. ausser das der flag, nebst inkludierung der header und lib datei und dem aufruf von CoInitialize().

    die fehlermeldung lautet: error C2065: 'BIF_NEWDIALOGSTYLE' : nichtdeklarierter Bezeichner.

    ohne diesen flag funktioniert das ganze auch .. aber ich hätte gerne die möglichkeit bei der verzeichnisauswahl auch ein neues zu erstellen.

    ///////////////////////////////////////////////////////////////////////////
    // DirDialog.cpp: implementation of the CDirDialog class.
    //////////////////////////////////////////////////////////////////////
    
    #include "stdafx.h"
    #include "DirDialog.h"
    #include "shlobj.h"
    
    #include "objbase.h"
    
    #ifdef _DEBUG
    #undef THIS_FILE
    static char THIS_FILE[]=__FILE__;
    #define new DEBUG_NEW
    #endif
    
    // Callback function called by SHBrowseForFolder's browse control
    // after initialization and when selection changes
    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;
    }
    
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    
    CDirDialog::CDirDialog()
    {
    	m_bStatus = FALSE;
    }
    
    CDirDialog::~CDirDialog()
    {
    }
    
    BOOL CDirDialog::DoBrowse(CWnd *pwndParent)
    {
    
    	CoInitialize(NULL);
    
        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
                        | BIF_NEWDIALOGSTYLE;
    
        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;
    }
    


  • Hast du ein aktuelles Platform SDK installiert?

    Öffne einfach mal die Datei shlobj.h mit einem Texteditor und such nach BIF_NEWDIALOGSTYLE. Ist es dort nicht drin, dann lad das neue Platform SDK runter.

    Der Wert von BIF_NEWDIALOGSTYLE ist 0x0040 falls du es schnell brauchst. 😉


Anmelden zum Antworten