CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2004
    Posts
    38

    open file window (open...)

    I have been looking for the answer but I couldn't find what I am looking for...
    I want, using API, open that window where it is possible to select a file. Almost all program has this option inside menu "file" >> "open..."

    I would like to know if there is any specific function to do that !! ?

    or any tutorial where I could get info about it.

    If someone knows the answer for that help me!

    Thanks

  2. #2
    Ejaz's Avatar
    Ejaz is offline Elite Member Power Poster
    Join Date
    Jul 2002
    Location
    Lahore, Pakistan
    Posts
    4,211

  3. #3
    Join Date
    Oct 2004
    Posts
    38

    Re: open file window (open...)

    This tutorial seems to be used with MFC...I would like to know what would give me the same result but with API.

    Thanks

  4. #4
    Ejaz's Avatar
    Ejaz is offline Elite Member Power Poster
    Join Date
    Jul 2002
    Location
    Lahore, Pakistan
    Posts
    4,211

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: open file window (open...)

    Code:
    char         szExtBuffer[MAX_PATH] = "";
    OPENFILENAME ofn;
    
    strcpy(szExtBuffer, "*.txt; *.log");
    
    ofn.lStructSize       = sizeof(ofn);
    ofn.hwndOwner         = 0;
    ofn.hInstance         = 0;
    ofn.lpstrFilter       = 0;
    ofn.lpstrCustomFilter = 0;
    ofn.nMaxCustFilter    = 0;
    ofn.nFilterIndex      = 0;
    ofn.lpstrFile         = szExtBuffer;
    ofn.nMaxFile          = MAX_PATH;
    ofn.lpstrFileTitle    = 0;
    ofn.nMaxFileTitle     = 0;
    ofn.lpstrInitialDir   = 0;
    ofn.lpstrTitle        = "Open file";
    ofn.Flags             = 0;
    ofn.nFileOffset       = 0;
    ofn.nFileExtension    = 0;
    ofn.lpstrDefExt       = 0;
    ofn.lCustData         = 0;
    ofn.lpfnHook          = 0;
    ofn.lpTemplateName    = 0;
    
    // Open dialog
    if(::GetOpenFileName(&ofn) == FALSE)
      // Cancel pressed

  6. #6
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: open file window (open...)

    Code:
    ofn.lStructSize       = sizeof(ofn);
    ofn.hwndOwner         = 0;
    ofn.hInstance         = 0;
    ofn.lpstrFilter       = 0;
    ofn.lpstrCustomFilter = 0;
    ofn.nMaxCustFilter    = 0;
    ofn.nFilterIndex      = 0;
    ofn.lpstrFile         = szExtBuffer;
    ofn.nMaxFile          = MAX_PATH;
    ofn.lpstrFileTitle    = 0;
    ofn.nMaxFileTitle     = 0;
    ofn.lpstrInitialDir   = 0;
    ofn.lpstrTitle        = "Open file";
    ofn.Flags             = 0;
    ofn.nFileOffset       = 0;
    ofn.nFileExtension    = 0;
    ofn.lpstrDefExt       = 0;
    ofn.lCustData         = 0;
    ofn.lpfnHook          = 0;
    ofn.lpTemplateName    = 0;
    This is too much code in my eyes, since it would go easier:

    Code:
    ZeroMemory(&ofn, sizeof(ofn));
    
    ofn.lStructSize       = sizeof(ofn);
    ofn.lpstrFile         = szExtBuffer;
    ofn.nMaxFile          = MAX_PATH;
    ofn.lpstrTitle        = "Open file";
    Or even better:

    Code:
    OPENFILENAME ofn = { 0 };
    
    ofn.lStructSize       = sizeof(ofn);
    ofn.lpstrFile         = szExtBuffer;
    ofn.nMaxFile          = MAX_PATH;
    ofn.lpstrTitle        = "Open file";
    Last edited by NoHero; February 3rd, 2005 at 10:56 AM.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  7. #7
    Join Date
    Oct 2004
    Posts
    38

    Re: open file window (open...)

    This discussion was very usefull
    Thank you all,

  8. #8
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: open file window (open...)

    Quote Originally Posted by NoHero
    This is too much code in my eyes, since it would go easier:
    This kind of depends on the actual parameters you want to set though...

  9. #9
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: open file window (open...)

    Quote Originally Posted by Andreas Masur
    This kind of depends on the actual parameters you want to set though...
    Of course. Since 80% of your code are zero setters, so you can make it smaller with my suggestion.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

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