mcisendstring 放不了音乐,完全没有声音,很简单的代码,但就是没声音
#include<windows.h>#pragmacomment(lib,"winmm.lib")voidmain(){mciSendString("playC:\1....
#include <windows.h>
#pragma comment (lib, "winmm.lib")
void main()
{
mciSendString("play C:\1.mp3", NULL,0,NULL);
} 展开
#pragma comment (lib, "winmm.lib")
void main()
{
mciSendString("play C:\1.mp3", NULL,0,NULL);
} 展开
2个回答
展开全部
首先传递路径字符串时传递了"play C:\1.mp3",单斜杠的话编译时会warning的,这个你没看到?
其次,多媒体播放要在gui程序中进行。控制台程序就别想这么弄了。这是主要问题所在。编写个win32 application的程序吧,肯定行。附上我的代码:
#include <windows.h>
#include "resource.h"
#pragma comment (lib,"winmm.lib")
BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_CLOSE:
DestroyWindow(hwndDlg);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
if(LOWORD(wParam)==IDB_PLAY)
{
mciSendString("play D:\\娱乐\\歌曲\\music\\爱江山更爱美人.mp3",NULL,NULL,NULL);
}
break;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_DIALOG),NULL,DialogProc,NULL);
return 0;
}
其次,多媒体播放要在gui程序中进行。控制台程序就别想这么弄了。这是主要问题所在。编写个win32 application的程序吧,肯定行。附上我的代码:
#include <windows.h>
#include "resource.h"
#pragma comment (lib,"winmm.lib")
BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_CLOSE:
DestroyWindow(hwndDlg);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
if(LOWORD(wParam)==IDB_PLAY)
{
mciSendString("play D:\\娱乐\\歌曲\\music\\爱江山更爱美人.mp3",NULL,NULL,NULL);
}
break;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_DIALOG),NULL,DialogProc,NULL);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询