Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone..

In WIN32, I wrote an application to play the audio/video files. In My system am having Windows Media Player & VLC media player.. When i execute my application, Video files will open with VLC Media player..
And, My question is: Programmatically how do i make video files to run with Windows media player default.. Even though, if i made the VLC Player as default player, My application should open the audio/video files in Windows media palyer..

The code to open the audio file is like this:

C++
void FileOpen(HWND hwnd,char exe_arr[100])
{
    OPENFILENAME ofn;           
    TCHAR szFile[MAX_PATH+1];   
    ZeroMemory(szFile, sizeof(szFile));
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hwnd;
    ofn.lpstrFile = szFile;
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrFilter = TEXT("All\0*.*\0Text\0*.TXT\0");
    ofn.nFilterIndex = 1;
    ofn.lpstrFileTitle = NULL;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = NULL;
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;

    
    if (GetOpenFileName(&ofn)==TRUE)  
    {  
        int ret = (int) ShellExecute(
                          hwnd,
                          NULL,
			  "E:\\Wildlife.wmv",
                          NULL,
                          TEXT("c:/windows/system32/"),
                          SW_SHOWNORMAL);
        if (ret <= 32)
        {  
            MessageBox(NULL, TEXT("Could not open this file"), TEXT("File I/O Error"), MB_ICONSTOP);  
            return;  
        }  
    }  
}


Is there any solution for this...??

Please suggest me..

Thanks in advance..

enhzflep: Added code-tags
Posted
Updated 16-Apr-12 2:25am
v3

1 solution

Well, the answer's actually fairly straight-forward.

Firstly, since Windows will open your media files by default with VLC, you can't rely on the 'usual' method involving ShellExecute, since that will also invoke VLC.

What you instead need to do is:

a) Locate the Windows Media Player executable
b) Locate the file you wish to play
c) construct a parameter-string to pass to WMP
d) call ShellExecute, with the full path to the wmplayer.exe file and the param-string from (c)

In practise, this code will play a file called "tada.wav", located in the same folder as your exe. (Tested on Win7 Home Premium)


C++
void playFileWithWMP()
{
    TCHAR progFileFolder[MAX_PATH];
    TCHAR *desiredFile = "Windows Media Player/wmplayer.exe";
    TCHAR mediaPlayerPath[MAX_PATH];
    TCHAR *fileToPlay = "tada.wav";
    TCHAR wmpParam[MAX_PATH];
    TCHAR defaultFolder[MAX_PATH];

    SHGetSpecialFolderPath(0, progFileFolder, CSIDL_PROGRAM_FILES, FALSE);
    strcpy(mediaPlayerPath, progFileFolder);
    strcat(mediaPlayerPath, "/");
    strcat(mediaPlayerPath, desiredFile);

    GetCurrentDirectory(MAX_PATH, defaultFolder);
    sprintf(wmpParam, "/play %s/%s", defaultFolder, fileToPlay);

    ShellExecute(NULL, NULL, mediaPlayerPath, wmpParam, NULL, SW_SHOW);
}
 
Share this answer
 
Comments
Guru_C++ 16-Apr-12 8:43am    
Hey.. Thank you so much..:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900