CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: CFileDialog

  1. #1
    Guest

    CFileDialog

    Hi,

    why is the following code not working? I get a debug assertion fault:

    CFileDialog dlgLoad(TRUE);
    dlgLoad.m_ofn.lpstrFilter = "HTML-Dateien\0*.htm;*.html";
    dlgLoad.m_ofn.lpstrFile = "*.htm;*.html";
    dlgLoad.m_ofn.lpstrInitialDir = "C:\\Eigene Dateien";
    dlgLoad.m_ofn.Flags = OFN_HIDEREADONLY;
    dlgLoad.DoModal();



    If I remove the lines with Flags and lptstrFile, everything is fine.

    Where's the problem?

    TIA,


    Fox20



  2. #2
    Join Date
    May 1999
    Location
    CA, USA
    Posts
    586

    Re: CFileDialog

    Here's an example of what the call should look like:

    void CYourDoc::OnFileOpen()
    {
    CString szTemp;

    szTemp = AfxGetApp()->GetProfileString("Folders", "OpenDefault");

    CFileDialog dlg(TRUE, _T("doc"), NULL,
    OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,
    _T("Type of Files (*.doc;*.xls)|*.doc;*.xls|All Files (*.*)|*.*||"));

    if (szTemp.GetLength() > 0)
    dlg.m_ofn.lpstrInitialDir = (LPCTSTR)szTemp;

    if (dlg.DoModal() != IDOK)
    {
    UpdateAllViews(NULL);
    return; // stay with old data file
    }

    // Blah, Blah, Blah....
    }


    Rail

    ------------
    Recording Engineer/Software Developer
    Rail Jon Rogut Software
    http://home.earthlink.net/~railro/
    [email protected]

  3. #3
    Guest

    Re: CFileDialog

    Is it not possible to use it the way I did it?


  4. #4
    Join Date
    May 1999
    Location
    CA, USA
    Posts
    586

    Re: CFileDialog

    With some changes... yes:

    CFileDialog dlgLoad(TRUE);

    // Change this slightly:

    dlgLoad.m_ofn.lpstrFilter = _T("HTML-Dateien (*.htm;*.html)\0|*.htm;*.html\0\0");

    dlgLoad.m_ofn.lpstrFile = _T("*.htm;*.html");

    dlgLoad.m_ofn.lpstrInitialDir = _T(C:\\Eigene Dateien");

    // You have to use a bitwise OR here:

    dlgLoad.m_ofn.Flags |= OFN_HIDEREADONLY;

    dlgLoad.DoModal();


    Rail

    ------------
    Recording Engineer/Software Developer
    Rail Jon Rogut Software
    http://home.earthlink.net/~railro/
    [email protected]

  5. #5
    Guest

    Re: CFileDialog

    Ok, the bitwise OR makes sense, but the debug assertion is still there. Any other idea why?

    TIA,


    Fox20


  6. #6
    Join Date
    May 1999
    Location
    CA, USA
    Posts
    586

    Re: CFileDialog

    No - other than the error in my code that I posted where I forgot to put a quote in the initial folder string, I tested this code on my system and it works perfectly.

    Where are you making the call?

    Rail

    ------------
    Recording Engineer/Software Developer
    Rail Jon Rogut Software
    http://home.earthlink.net/~railro/
    [email protected]

  7. #7
    Guest

    Re: CFileDialog

    well, thanks anyway


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured