SFML community forums

Help => General => Topic started by: Msquared on January 21, 2014, 09:25:30 pm

Title: Enable user to open file
Post by: Msquared on January 21, 2014, 09:25:30 pm
I'm trying to write a program which involves the user selecting an audio file on their computer to open, the problem is I have no idea where to even begin on this. Is it possible in SFML to open the file explorer and have the user select a file that way, similar to the way someone would if they were opening a save word document? If not in sfml, is there another way to do this?
Title: Re: Enable user to open file
Post by: Lignum on January 21, 2014, 09:33:12 pm
SFML can't do this as far as I know. However, on Windows you can use the Windows API to get what you want (http://msdn.microsoft.com/en-us/library/windows/desktop/bb776913%28v=vs.85%29.aspx#basic_usage). The only downside is that it's not portable.
Title: Re: Enable user to open file
Post by: FRex on January 21, 2014, 10:52:00 pm
There is no way to do it in SFML, if you're desperate you can try do it separately for each platform:

Windows -> must be function in win api
Linux -> easiest way imo = zenity + popen, zenity is not guaranteed to be present but it's really common
Mac -> there probably is a function in cocoa for that

Or you could write standalone cross platform program in any language that uses real toolkit(preferably something with drag and drop GUI designer, like Qt, Lazarus etc.) which only launches a dialog and then writes path to a file, then in your c++ program you'd execute that program with system() and read the file content to get the path.
Title: Re: Enable user to open file
Post by: math1992 on January 21, 2014, 11:08:34 pm
I am actually working on a file selector window for Window (The OS, It's the one I use).

If you are using Window and you are interessed in my project, I could send you the source code (There is some bugs left, but it works pretty well) :D
Title: Re: Enable user to open file
Post by: Azaral on January 22, 2014, 12:37:36 am
I had a simple level editor I was making and the user would type in the file location to open files. Worked on my machine (Windows) and I don't see why it wouldn't work on the other two OS.
Title: Re: Enable user to open file
Post by: AlejandroCoria on January 22, 2014, 01:06:18 am
I normally use "dirent.h" to access a directory and get the files. This is part of the standard POXIS, but in Windows, some compilers do not include (such as Microsoft Visual C++), but you can get the header and add it.

The downside is that it is made to C. In C++ I think you would have to use Boost in place, but I never used it.
Title: Re: Enable user to open file
Post by: eXpl0it3r on January 22, 2014, 01:15:15 am
Entering the path will essentially always work, but it's not really user friendly.

If you want a directory choosing popup like every other Windows application shows, that can be "easily" done with some WinAPI calls and there are most likely similar API calls on other OS. You could also look at how Qt does it.

The dirent.h header is a way, but I wouldn't really advise to take that way. If you want to create your own directory listing, you nearly can't go around using Boosts Filesystem. ;)
Title: Re: Enable user to open file
Post by: Msquared on January 22, 2014, 01:29:22 am
SFML can't do this as far as I know. However, on Windows you can use the Windows API to get what you want (http://msdn.microsoft.com/en-us/library/windows/desktop/bb776913%28v=vs.85%29.aspx#basic_usage). The only downside is that it's not portable.
Thanks, that might come in handy. I'd rather not use win API but if I have to its not the end of the world.

I am actually working on a file selector window for Window (The OS, It's the one I use).

If you are using Window and you are interessed in my project, I could send you the source code (There is some bugs left, but it works pretty well) :D
If you could send it too me that would be great. I'll see if it works with what I'm doing.
Title: Re: Enable user to open file
Post by: math1992 on January 22, 2014, 05:46:48 am
However, I don't know how to send a complete project on this forum. :'(
Title: Re: Enable user to open file
Post by: zsbzsb on January 22, 2014, 06:28:41 am
However, I don't know how to send a complete project on this forum. :'(

Title: Re: Enable user to open file
Post by: math1992 on January 22, 2014, 09:58:35 pm
Msquared I send you a eMail on member acount to continue the conversation in private, please go see it.

Thanks.