Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

MS VC++ Getting a File Name Dialog (not using MFC)

I may be having a pipe dream, but I thought there was a function you could call that would open up the 'File Dialog' and upon exit would return the string to where the user had pointed.
I am using Visual C++ 6.0
I am NOT using MFC.

Thanks
-Vision
0
Vision
Asked:
Vision
  • 5
  • 2
1 Solution
 
akshayxxCommented:
>>>I am using Visual C++ 6.0
>>>I am NOT using MFC.

what are you using then ??
it is possible only if you are using some GUI library .. MFC is one .. there are more.. tell me what library are you working with ..
0
 
akshayxxCommented:
definitely no such 'standard C/C++' function.. these are implemented and hence provided by GUI libraries
0
 
frogger1999Commented:
using winapi

int main()

{
    OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.lpstrFileTitle = new char[255];
    ZeroMemory(ofn.lpstrFileTitle, 255);
    ofn.nMaxFileTitle = 255;
   
    GetOpenFileName(&ofn);

    std::cout<<ofn.lpstrFileTitle;
    delete ofn.lpstrFileTitle;
    return 0;
}


this is a very simple example and there are better ones on msdn.  Look for GetOpenFileName or GetSaveFileName

some of the options are custom filters for extensions a custom start path, multi selection, about everything anyone would need.

Hope this helps


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
frogger1999Commented:
oh yeah for the complete path use this

int main()

{
    OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.lpstrFile = new char[255];
    ZeroMemory(ofn.lpstrFile, 255);
    ofn.nMaxFile = 255;
   
    GetOpenFileName(&ofn);

    std::cout<<ofn.lpstrFile;
    delete ofn.lpstrFile;
    return 0;
}
0
 
frogger1999Commented:
whoops this is c...

replace new with malloc of course and cout with printf

sorry about that
0
 
frogger1999Commented:
better yet use a stack variable

my 100% C version

#include <windows.h>
#include <stdio.h>

int main()

{
    char x[255];
    OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.lpstrFile = x;
    ZeroMemory(ofn.lpstrFile, 255);
    ofn.nMaxFile = 255;
    GetOpenFileName(&ofn);
    printf("%s", ofn.lpstrFile);
    return 0;
}
0
 
VisionAuthor Commented:
Fantastic!  This is *EXACTALLY what I was looking for.  For your speed (and accuracy) I've doubled the points.  

I will mention that the only thing I had to add to your list was this include:
#include "commdlg.h"

And, for the record, I was using the Windows API, in a more 'c' like environment.  

Again, thanks for the help Frogger.
-Vision
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now