Datei-Explorer zum Öffnen von Dateien nutzen?



  • Moin,

    die Überschrift sagt eigentlich schon alles.

    Ich möchte dieses kleine Fenster, das immer kommt, wenn man eine Datei öffnen möchte, aufrufen/programmieren etc.

    Ich hoffe auf Hilfe,

    Euer ItsNotYou

    P.S.: Ich verstehe C, nicht C++. Deshalb hoffe ich bei Beispielen auf C.





  • Ich habe mir jetzt von MSDN mir das Beispiel vorgenommen und abgewandelt:

    void OpenFile()
    {
        OPENFILENAME ofn;
        char szFile[300];
        HWND hwnd;
        HANDLE hf;
    
        ZeroMemory(&ofn, sizeof(ofn));
    
        ofn.lStructSize = sizeof(ofn);
        ofn.hwndOwner = hwnd;
        ofn.lpstrFile = szFile;
        ofn.lpstrFile[0] = '\0';
        ofn.nMaxFile = sizeof(szFile);
        ofn.lpstrFilter = "Alle\0*.*\0Wave\0*.wav\0Mp3\0*.mp3\0Midi\0*.mid\0";
        ofn.nFilterIndex = 1;
    //    ofn.lpstrFileTitle = NULL;
    //    ofn.nMaxFileTitel = 0;
    // Mein Compiler sieht diese beiden als "Überflüssig" an
        ofn.lpstrInitialDir = NULL;
        ofn.Flags = OFN_PATHMUSTEXIST | OFN_PATHMUSTEXIST;
    
        if(!GetOpenFileName(&ofn))
        {
            return;
        }
    
        hf = CreateFile(ofn.lpstrFile, GENERIC_READ, 0, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL);
    
        int ende = 0;
        int count = 0;
    
        for(count = 0;;count++)
        {
            switch(szFile[count])
            {
                case '.':
                    if((szFile[count+1] == 'w') && (szFile[count+2] == 'a') && (szFile[count+3] == 'v'))
                    {
                        char befehl[320];
                        wsprintf(befehl, "open \"%s\" alias WAVE", szFile);
                        mciSendString(befehl, 0, 0, 0);
                    }
                    else if((szFile[count+1] == 'm') && (szFile[count+2] == 'p') && (szFile[count+3] == '3'))
                    {
                        char befehl[320];
                        wsprintf(befehl, "open \"%s\" alias MP3", szFile);
                        mciSendString(befehl, 0, 0, 0);
                    }
                    else if((szFile[count+1] == 'm') && (szFile[count+2] == 'i') && (szFile[count+3] == 'd'))
                    {
                        char befehl[320];
                        wsprintf(befehl, "open \"%s\" alias MIDI", szFile);
                        mciSendString(befehl, 0, 0, 0);
                    }
            }    
        }
        return;
    }
    

    Wenn ich jetzt diese Funktion aufrufe... kommt nichts.

    Warum?

    Euer ItsNotYou



  • Platform SDK schrieb:

    lpstrFilter
    Pointer to a buffer containing pairs of null-terminated filter strings. The last string in the buffer must be terminated by two NULL characters.

    Ansonsten frag doch einfach GetLastError() warum die GetOpenFileName() nicht will...



  • 1.) Wenn du kein anderes Hauptfenster hast bei hwndOwner einfach NULL angeben.
    2.) Hört sich blöd an, aber rufst du OpenFile auch auf 🙄 😉



  • Ich rufe die Funktion "OpenFile()" auf, wenn ein Button gedrückt wurde.



  • Was sagt der Debugger?

    Bis zu welcher Zeile geht das Programm, bevor es die Funktion nichtstuhend verläßt?


Anmelden zum Antworten