使用WIN32将Windows Media Player设置为音频文件的默认设置 [英] To make Windows Media Player as default for audio files using WIN32

查看:166
本文介绍了使用WIN32将Windows Media Player设置为音频文件的默认设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..

在WIN32中,我编写了一个应用程序来播放音频/视频文件.在我的系统中,有Windows Media Player& VLC媒体播放器..当我执行我的应用程序时,视频文件将使用VLC媒体播放器打开..
而且,我的问题是:以编程方式如何使视频文件默认与Windows Media Player一起运行.即使将VLC Player设置为默认播放器,我的应用程序也应该在Windows Media Palyer中打开音频/视频文件.

打开音频文件的代码如下:

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:

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;  
        }  
    }  
}



有什么解决方案吗... ??

请给我建议.

提前谢谢..

enhzflep:添加了代码标签



Is there any solution for this...??

Please suggest me..

Thanks in advance..

enhzflep: Added code-tags

推荐答案

嗯,答案实际上很简单.

首先,由于Windows默认情况下会使用VLC打开您的媒体文件,因此您不能依赖于涉及ShellExecute的常规"方法,因为这也会调用VLC.

相反,您需要做的是:

a)找到Windows Media Player可执行文件
b)找到您要播放的文件
c)构造一个参数字符串以传递给WMP
d)调用ShellExecute,使用wmplayer.exe文件的完整路径和(c)中的param-string
实际上,此代码将播放一个名为"tada.wav"的文件,该文件与您的exe位于同一文件夹中. (在Win7 Home Premium上测试)


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)


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);
}


这篇关于使用WIN32将Windows Media Player设置为音频文件的默认设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆