Datei aus Programm starten



  • Hallo.

    Ich habe folgendes Problem, ich müchte aus meinem Programm zum Beispiel eine *.mp3-Datei starten. Aber nich in meinem Programm, sondern soll sich zum Beispiel der Windows Media Player öffnen und die Datei abspielen.
    Am besten wäre es wenn das Programm die Datei immer mit dem bevorzugten Programm öffnet, also wenn ich ITunes benutzen würde, das sich die Datei mit ITunes öffnet. Halt als ob man doppelklickt auf die Datei.

    Vielen Dank!



  • Dieser Thread wurde von Moderator/in evilissimo aus dem Forum C++ in das Forum WinAPI verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.



  • Hi,

    so müsste es gehen. Du musst nur den Pfad ändern.

    #include <windows.h> 
    
    int main() 
    { 
       ShellExecute(NULL,"open","C:\\Beispiel.wma",NULL,NULL,SW_NORMAL); 
    }
    


  • Bin mir nicht sicher glaube aber du musst anstatt "open" "start" nehmen.

    Open ist nämlich kein consolenbefehl

    mfg



  • evtl tuts auch shcon ein WinExec

    also WinExec("cmd /C start c:\...\file.mp3",0);



  • c°h° schrieb:

    Bin mir nicht sicher glaube aber du musst anstatt "open" "start" nehmen.

    Open ist nämlich kein consolenbefehl

    mfg

    HINSTANCE ShellExecute(
    HWND hwnd,
    LPCTSTR lpOperation,
    LPCTSTR lpFile,
    LPCTSTR lpParameters,
    LPCTSTR lpDirectory,
    INT nShowCmd
    );

    lpOperation
    [in] Pointer to a null-terminated string, referred to in this case as a verb, that specifies the action to be performed. The set of available verbs depends on the particular file or folder. Generally, the actions available from an object's shortcut menu are available verbs. For more information about verbs and their availability, see Object Verbs. See Extending Shortcut Menus for further discussion of shortcut menus. The following verbs are commonly used.

    edit
    Launches an editor and opens the document for editing. If lpFile is not a document file, the function will fail.
    explore
    Explores the folder specified by lpFile.
    find
    Initiates a search starting from the specified directory.
    open
    Opens the file specified by the lpFile parameter. The file can be an executable file, a document file, or a folder.
    print
    Prints the document file specified by lpFile. If lpFile is not a document file, the function will fail.
    NULL

    For systems prior to Microsoft Windows 2000, the default verb is used if it is valid and available in the registry. If not, the "open" verb is used.

    For Windows 2000 and later systems, the default verb is used if available. If not, the "open" verb is used. If neither verb is available, the system uses the first verb listed in the registry.

    http://msdn.microsoft.com/library/?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp


Anmelden zum Antworten