Get the return value of a windows explorer

What I want to do is get the directory of a file. I want to open a Windows explorer, have the user select their file and click 'Open'. Example: In notepad, you can click File->Open... and it will pull up the window I want to create.

If anyone knows a function to do this, or knows a workaround, etc. please reply.
closed account (Dy7SLyTq)
ummm honestly i dont know, but i would suggest looking in the win32 api
hmmm
I do need a console for this though. You know, even programs that I am sure are not all built with win32 have a open, or a save window. Does any one here have any experience with how?
Thanks
That is exactly what I am looking for!

I have tried this function but the file outputs nothing at the end.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
bool OpenMusic()
{
	OPENFILENAME ofn;
	string file;
	ZeroMemory( &ofn , sizeof( ofn));
	ofn.lStructSize = sizeof ( ofn );
	ofn.hwndOwner = NULL ;
	ofn.lpstrFile = LPSTR(file.c_str()) ;
	ofn.lpstrFile[0] = '\0';
	ofn.nMaxFile = sizeof( file );
	ofn.lpstrFilter = "All Music Files\0*.wav\0*.ogg\0*.mp3\0*.mp4";
	ofn.nFilterIndex =1;
	ofn.lpstrFileTitle = NULL ;
	ofn.nMaxFileTitle = 0 ;
	ofn.lpstrInitialDir=NULL ;
	ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST ;
	GetOpenFileName( &ofn );
	ShowConsole();
	cout << file;
	Sleep(3000);
	HideConsole();
	
	return theMusic.openFromFile(file);
}


Can you tell me what the problem is?

Again, file does not output anything on line 19

The twin GetSaveFileName() is also very useful as I have to do both.

EDIT: I am using SFML as well
Last edited on
BREAKING NEWS:

I just got it fixed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
bool OpenMusic()
{
	OPENFILENAME ofn;
	char file[100];
	ZeroMemory( &ofn , sizeof( ofn));
	ofn.lStructSize = sizeof ( ofn );
	ofn.hwndOwner = NULL ;
	ofn.lpstrFile = file;
	ofn.lpstrFile[0] = '\0';
	ofn.nMaxFile = sizeof( file );
	ofn.lpstrFilter = "All Music Files\0*.wav\0*.ogg\0*.mp3\0*.mp4";
	ofn.nFilterIndex =1;
	ofn.lpstrFileTitle = NULL ;
	ofn.nMaxFileTitle = 0 ;
	ofn.lpstrInitialDir=NULL ;
	ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST ;
	GetOpenFileName( &ofn );
	ShowConsole();
	cout << file;
	Sleep(3000);
	HideConsole();
	
	return theMusic.openFromFile(file);
}


The problem seemed to be that I was converting from LPSTR to string. Maybe c_str() was just returning a copy of the char[] version. Anyway, problem solved!

Thanks modoran! (again)
Topic archived. No new replies allowed.