?
Solved

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

Posted on 2003-03-03
8
Medium Priority
?
252 Views
Last Modified: 2010-04-15
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
Comment
Question by:Vision
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 8

Expert Comment

by:akshayxx
ID: 8061790
>>>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
 
LVL 8

Expert Comment

by:akshayxx
ID: 8061791
definitely no such 'standard C/C++' function.. these are implemented and hence provided by GUI libraries
0
 
LVL 1

Expert Comment

by:frogger1999
ID: 8062654
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:frogger1999
ID: 8062670
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
 
LVL 1

Expert Comment

by:frogger1999
ID: 8062720
whoops this is c...

replace new with malloc of course and cout with printf

sorry about that
0
 
LVL 1

Accepted Solution

by:
frogger1999 earned 800 total points
ID: 8062769
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
 
LVL 1

Author Comment

by:Vision
ID: 8066472
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question