listbox

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
maitrelame2
Posts: 26
Joined: Sun Jan 21, 2007 9:11 pm

listbox

Post by maitrelame2 »

I want to open a music with my mp3 player but I need to get the filename+the repertory...

Code: Select all

{
                 listbox->addItem(L"Open a sound");
                 env->addFileOpenDialog(L"Please selecte a sound");
                 return true;
              }
I juste to get a string like ..\media\my.mp3...
Could you help plz
Irrlicht 4ever.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

i dont know how to implement it technicaly, but the idea should be like this: read sounds directory, show all files using for loop. for more info read documentatuon. http://msdn.microsoft.com/ if you are using vc++
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

device->getFileSystem()->getAbsolutePath("./some/thing.ok");
returns something like "c:\\path\\to\\some\\thing.ok"
is that what you meant?
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
maitrelame2
Posts: 26
Joined: Sun Jan 21, 2007 9:11 pm

Post by maitrelame2 »

Not realy I mean that I want to select a file in listbox, and after get the directorie and the file name like :

I go on C:\-->Programm files --> musique --> lol.mp3
And clic on ok
then i get a string that give me : C:\Programm files\musique\lol.mp3
Then I send it to FSOUND_STREAM play(string song);
so it play the sound I select before...
Irrlicht 4ever.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

then you want the absolute path? in that case, getAbsolutePath is what you need
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
maitrelame2
Posts: 26
Joined: Sun Jan 21, 2007 9:11 pm

Post by maitrelame2 »

Thank you but how to store in a string ?
Irrlicht 4ever.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

by typecasting maybe
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

(roxaz go learn c++ and read more thoroughly)

core::stringc longname = getAbsolutePath(filename);
const char* path = longname.c_str();

But beware that char* can be complex to handle correctly. Better use stringc throughout your program and only pass the c_str() to system and Irrlicht functions where necessary.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

my bad :oops:
maitrelame2
Posts: 26
Joined: Sun Jan 21, 2007 9:11 pm

Post by maitrelame2 »

I doesn't work...

Code: Select all

              if (id == 103)
              {
                 listbox->addItem(L"Ouvrir un morceau ");
                 env->addFileOpenDialog(L"Veuillez choisir un fichier");
                 std::string filename;
                 core::stringc longname = getAbsolutePath(filename); 
                 return true;
              }
message devcpp : 'getAbsolutePath' undeclared {first use this function}
I think that's because I use irrlicht 1.1...
I don't realy want to change with irrlicht 1.2, because the loop is not the same...
I receive the error :
Filename undeclarred...
Irrlicht 4ever.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Hehe, maybe you also need a C++ freshup? The longfilename was just an example how to store the result in a string. If you make this string local to the if block it will of course be gone after the block.
More problems: bitplane already gave you the complete method call path for getAbsolutePath, so use that one. But be sure that your device pointer is valid.
Just adding the FileDialog is not enough. You have to get the filename from the dialog and maybe close the dialog. And using std::string is not necessary at all.

@roxaz: Never mind, but some of your suggestions are really dangerous. So take your time and develop your skills with Irrlicht :wink:
maitrelame2
Posts: 26
Joined: Sun Jan 21, 2007 9:11 pm

Post by maitrelame2 »

I don't understand can you just writte two lines of codes for show it to me plz...
Irrlicht 4ever.
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

maitrelame2 wrote:I don't understand can you just writte two lines of codes for show it to me plz...
I don't understand why someone can't learn a language before they attempt to use it...
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

getFileSystem()->getAbsolutePath("./some/thing.ok");

The function is part of the filesystem class. I suggest you do as zeno says...

And why are you using "filename"? Delete that one... :?

Actually forget all of that and just read a C++ book :P. Because you will run into 100 more errors anyway if you don't know what your doing.

Ok dont read a C++ book actually its better to have a look through the code for the meshviewer example.
Athlon_Jedi
Posts: 156
Joined: Wed Jul 21, 2004 4:29 am
Location: Mishawaka, In

OMG !!!

Post by Athlon_Jedi »

umm yea more C++ experiance would defanatly help.

Code: Select all


if (id == 103) 
              { 
                 listbox->addItem(L"Ouvrir un morceau "); 
                 env->addFileOpenDialog(L"Veuillez choisir un fichier"); 
                 std::string filename; 
                 core::stringc longname = getAbsolutePath(filename); 
                 return true; 
              }

this is in the local scope!!!

you must add:

Code: Select all


IGUIListBox* listbox = 0;  //<-- declarations for variables

//and this

IGUIEnvironment* env = 0; //<-- this too is needed since this is in local scope 

and this: getAbsolutePath(filename); is a function not a variable you you must also declare the ACTUAL FILE NAME YOU WANT not just filename.

i.e. std::string = NAME_OF_FILE_HERE;
then getAbsolutePath( "NAME_OF_FILE" )


within your braces so listbox is declared in the function.

this has nothing to do with irrlicht!!!

this is proper C++ practice.

a C++ tip, when you have a local function such as this, unless you are using a class to define all your varibles, you must explicitly declare the functions you want to use. basic C++ knowledge tells us that unless declared public with a class, functions in the LOCAL SCOPE have no access to functions in the GLOBAL SCOPE until declared within the fuction.
Post Reply