本文介绍了使用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

推荐答案

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设置为音频文件的默认设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:55