• C

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
LVL 1
VisionAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.