Re: document view window "Open File" button behavior
 
Looking further into the SHBrowseForFolder function's documentation
and finding more examples, I have something like this for my overriden
DoPromptFileName function:
BOOL CDocManagerEx::DoPromptFileName( CString& fileName, UINT
nIDSTitle,
                                     DWORD lFlags, BOOL bOpenFileDialog,
                                     CDocTemplate* pTemplate )
{
    BROWSEINFO binfo = { NULL };
    binfo.lpszTitle = _T("Pick a Directory");
    CoInitialize(NULL);
    LPITEMIDLIST pidl = SHBrowseForFolder ( &binfo );
    if ( pidl != 0 )
    {
        // get the name of the folder
        TCHAR path[MAX_PATH];
        if ( SHGetPathFromIDList ( pidl, path ) )
        {
            _tprintf ( _T("Selected Folder: %s\n"), path );
        }
        // free memory used
        IMalloc * imalloc = 0;
        if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
        {
            imalloc->Free ( pidl );
            imalloc->Release ( );
        }
        LPSTR fnameptr = fileName.GetBuffer(MAX_PATH);
        memcpy(fnameptr, &path[0], MAX_PATH*sizeof(char));
        fileName.ReleaseBuffer();
    }
    return pidl != NULL;
}
However, when I click the Open File button, I always get a textbox
message saying 'Access to "folder directory" is denied'. From looking
at the parameters of the function, I tried to reverse-engineer this
block of code to make sure pTemplate is used:
CString strFilter;
    CString strDefault;
    if (pTemplate != NULL)
    {
        ASSERT_VALID(pTemplate);
        AppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate,
&strDefault);
    }
    else
    {
        // do for all doc template
        POSITION pos = m_templateList.GetHeadPosition();
        BOOL bFirst = TRUE;
        while (pos != NULL)
        {
            pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
            AppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate,
                bFirst ? &strDefault : NULL);
            bFirst = FALSE;
        }
    }
I'm not sure how to otherwise obtain the OPENFILENAME structure,
particularly if I used SHBrowseForFolder instead of normal
CFileDialog. But anyhow, any suggestions on dealing with the
permissions problem?