Folgender Code funktioniert einwandfrei bei mir:
#include <acknex.h>
#include <windows.h>
#include <default.c>
SOUND* playme;
STRING* OB_E_NAME_STR;
function call_music()
{
OPENFILENAME my_file;
char buf[256];
FillMemory (&my_file,sizeof(my_file),0);
FillMemory (buf,256,0);
my_file.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST;
my_file.lStructSize = sizeof(my_file);
my_file.hwndOwner = hWnd;
my_file.lpstrFilter = "Musicfiles (*.mp3; *.wav; *.mid; *.ogg) \0*.mp3;*.ogg;*.wav;*.mid\0\0";
my_file.lpstrInitialDir = _chr("");
my_file.lpstrFile = buf;
my_file.nMaxFile = 255;
my_file.lpstrTitle = "Load Musicfile:";
while (key_any) wait(1);
if (GetOpenFileName(&my_file))
{
str_cpy (OB_E_NAME_STR,my_file.lpstrFile);
// add here the things to play the music. OB_E_NAME_STR is the name of the file. Example:
// playme = snd_create(OB_E_NAME_STR); shandle = snd_play(...);
}
}
void main()
{
level_load(NULL);
on_o = call_music;
}
Mit der der o-Taste (O wie Omega) lässt sich nun ein Datei-Öffnen Dialog öffnen.
Die Startposition legt diese Zeile fest:
my_file.lpstrInitialDir = _chr("");
Wenn du dort einen leeren String reinschreibst (wie im Beispiel) dann wird der Ordner "Eigene Dateien" geöffnet.
Alternativ kannst du einen beliebigen Pfad angeben.
Falls du den Ordner nutzen willst in dem dein Programm liegt solltest du dir
work_dir:
http://www.conitec.net/beta/awork_dir.htmoder
exe_dir:
http://www.conitec.net/beta/aexe_dir.htmanschauen und nutzen.