open file dialog

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.
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

open file dialog

Post by Cleves »

Hey all,

I did a open file dialog and i want the save the file that the user clicked on.
I'm trying to use getfilename but it dosen't work.can you show me plz how to use it?
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

anyone?^^

i wanted to ask as well is there anyway to show only certain files in the open dialog file?
plz help :D

Thanks
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

From the way the documentation reads, this is not currently possible.

You could make your own File list using the IGUIListBox or your own handcrafted interface.
Crud, how do I do this again?
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

Can someone plz show me how to get the filename of the selected file?
i can't get it working :(
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

wchar_t* FileName = myGUIFileOpen->getFilename();
Crud, how do I do this again?
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

That's exaclty what i have done but he writes violation accsess:
here is my code:

env->addFileOpenDialog(L"Please choose a file.");
IGUIFileOpenDialog* opendlg=0;
const wchar_t* FileName = opendlg->getFilename();
Thanks
Guest

Post by Guest »

Yeah because opendlg is a pointer pointing to nothing, so of course you will get a access violation, when you are trying to derefrence it, and the program can't access that spot in memory (0 == NULL).
.
I haven't used the UserInterface Classes yet, but i believe you have to do something like this:

Code: Select all


IGUIFileOpenDialog* opendlg = env->addFileOpenDialog(L"Please choose a file.");

const wchar_t* FileName = opendlg->getFilename();

Sfin
Posts: 13
Joined: Wed Oct 15, 2003 9:13 pm

Post by Sfin »

IT was me again. I am getting tired of having to do these double posts everytime I forget to login :P

Anyway it was me that posted the above. So please tell me if it works, that way I don't have to scratch my head trying to get it to work when I need it ;)
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

Yes, it works now.Thank you.
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

mmm when i'm trying to print out what is inside FileName it comes out as 0x00035.How can i know the name of the file?
What i'm trying to do is that the user picks up a mesh file(3ds,obj,etc)
and it loads it and shows it up.Is it possiable?

Thanks
Sfin
Posts: 13
Joined: Wed Oct 15, 2003 9:13 pm

Post by Sfin »

I think you might need to dereference FileName with *

so

cout << *FileName;
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

Well i tried what you said but he returnes 0 even if i did choose a file.
Here is my code:

IGUIFileOpenDialog* opendlg = env->addFileOpenDialog(L"Please choose a file.");
const wchar_t* FileName = opendlg->getFilename();
ofstream fout("output.txt");
fout << *FileName << "\n";
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

Could the problem be that the user hasn't been able to select a file in the split second between opening the window and it checking what is being selected?

This isn't VB where the program will wait for the dialog box to be dealt with.

You would have to do the getFileName() during your event handler.

Code: Select all

if (event.EventType == EET_GUI_EVENT){
   if (event.GUIEvent.EventType ==EGET_FILE_SELECTED){
      const wchar_t* FileName = opendlg->getFilename(); 
   }
}
Crud, how do I do this again?
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

Yep it works but i'm still getting numbers then the name of the file :?
Gorgon Zola
Posts: 118
Joined: Thu Sep 18, 2003 10:05 pm
Location: switzerland

Post by Gorgon Zola »

Cleves wrote:...but i'm still getting numbers then the name of the file :?
hm could it be that you use a char outputstream instead of a wchar??
I'm not sure if that matters with C++?
I wouldd try to convert the wchar string to a normal character string and then output it...

Code: Select all

std::string to_string(const wchar_t* msg){
  std::locale loc1 ( "english" );
  char str2 [255];
  std::use_facet<std::ctype<wchar_t> > ( loc1 ).narrow( msg, msg + wcslen(msg), 'X', &str2[0] );
  str2[wcslen(msg)] = '\0';
  std::string result(str2);
  return result;
}
tell me if it works :)
cheers
gorgon
Post Reply