Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Enable user to open file  (Read 5572 times)

0 Members and 1 Guest are viewing this topic.

Msquared

  • Newbie
  • *
  • Posts: 2
    • View Profile
Enable user to open file
« 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?

Lignum

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Enable user to open file
« Reply #1 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. The only downside is that it's not portable.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Enable user to open file
« Reply #2 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.
Back to C++ gamedev with SFML in May 2023

math1992

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • Email
Re: Enable user to open file
« Reply #3 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

Azaral

  • Full Member
  • ***
  • Posts: 110
    • View Profile
Re: Enable user to open file
« Reply #4 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.

AlejandroCoria

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
    • alejandrocoria.games
    • Email
Re: Enable user to open file
« Reply #5 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Enable user to open file
« Reply #6 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Msquared

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Enable user to open file
« Reply #7 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. 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.

math1992

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • Email
Re: Enable user to open file
« Reply #8 on: January 22, 2014, 05:46:48 am »
However, I don't know how to send a complete project on this forum. :'(

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Enable user to open file
« Reply #9 on: January 22, 2014, 06:28:41 am »
However, I don't know how to send a complete project on this forum. :'(

  • Make your project a git repo
  • Signup on Bitbucket (if you want private repos) or Github (if you like public repos)
  • Create repo on said hosting site
  • Push to repo on said hosting site
  • Share link to repo on said hosting site
  • Profit!!! (yea its late, im tired, so what, but yea this is the right way to do it  :) )
« Last Edit: January 22, 2014, 09:59:45 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

math1992

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • Email
Re: Enable user to open file
« Reply #10 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.