用C语言编写音乐播放器的代码 5

用单片机实现... 用单片机实现 展开
 我来答
南柯全栈开发
2011-03-01 · 还没有填写任何签名哦
南柯全栈开发
采纳数:139 获赞数:713

向TA提问 私信TA
展开全部
vc6.0下编译可以的

#include <windows.h>
#include <mmsystem.h>

#pragma comment (lib, "winmm.lib")

#define ID_PLAY 1000
#define ID_STOP 1001
#define ID_EXIT 1002

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
TCHAR clsName[] = TEXT ("clsMusicPlayer");
TCHAR title[] = TEXT ("Music Player");
WNDCLASS wc;
HWND hWnd;
MSG msg;
int cxScreen;
int cyScreen;
int winX;
int winY;
int winWidth;
int winHeight;

wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
wc.hCursor = LoadCursor (hInstance, IDC_ARROW);
wc.hIcon = LoadIcon (hInstance, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = clsName;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;

if ( !RegisterClass (&wc) )
{
MessageBox (NULL, TEXT ("RegisterClass Error"), TEXT ("ERROR"), MB_OK | MB_ICONINFORMATION);
return -1;
}

cxScreen = GetSystemMetrics (SM_CXSCREEN);
cyScreen = GetSystemMetrics (SM_CYSCREEN);

winWidth = cxScreen / 4;
winHeight = cyScreen / 3;
winX = (cxScreen - winWidth) / 2;
winY = (cyScreen - winHeight) / 2;

hWnd = CreateWindow (
clsName, title,
WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX,
winX, winY, winWidth, 100,
NULL, NULL, hInstance, NULL);

if ( !hWnd )
{
MessageBox (NULL, TEXT ("CreateWindow Error"), TEXT ("ERROR"), MB_OK | MB_ICONINFORMATION);
return -2;
}

ShowWindow (hWnd, SW_SHOW);
UpdateWindow (hWnd);

while ( GetMessage (&msg, NULL, 0, 0) > 0 )
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}

return msg.wParam;
}

int PlayMusic ()
{
HANDLE hFind;
WIN32_FIND_DATA findFileData;

static TCHAR szPath[1024] = TEXT (".\\*.wav");

hFind = FindFirstFile (szPath, &findFileData);
if ( hFind != INVALID_HANDLE_VALUE )
{
//MessageBox (NULL, findFileData.cFileName, "", 0);
PlaySound (findFileData.cFileName, NULL, SND_FILENAME | SND_ASYNC);
while ( FindNextFile (hFind, &findFileData) )
{
//MessageBox (NULL, findFileData.cFileName, "", 0);
PlaySound (findFileData.cFileName, NULL, SND_FILENAME | SND_ASYNC);
}
}
else
{
MessageBox (NULL, "没找到文件", "", 0);
}
return 1;
}

LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hDc;
PAINTSTRUCT ps;
HINSTANCE hInst;
RECT rect;

switch ( message )
{
case WM_CREATE:
{
GetClientRect (hWnd, &rect);
hInst = ((LPCREATESTRUCT)lParam)->hInstance;
CreateWindow (
"button",
TEXT ("播放"),
BS_DEFPUSHBUTTON | WS_VISIBLE | WS_CHILD,
rect.right / 10, rect.bottom / 10, 40, 25, hWnd, (HMENU)ID_PLAY, hInst, NULL);
CreateWindow (
"button",
TEXT ("停止"),
BS_DEFPUSHBUTTON | WS_VISIBLE | WS_CHILD,
rect.right / 10 + 50, rect.bottom / 10, 40, 25, hWnd, (HMENU)ID_STOP, hInst, NULL);
CreateWindow (
"button",
TEXT ("退出"),
BS_DEFPUSHBUTTON | WS_VISIBLE | WS_CHILD,
rect.right / 10 + 100, rect.bottom / 10, 40, 25, hWnd, (HMENU)ID_EXIT, hInst, NULL);
}
break;
case WM_COMMAND:
{
switch ( HIWORD (wParam) )
{
case BN_CLICKED:
{
switch ( LOWORD (wParam) )
{
case ID_PLAY:
{
PlayMusic ();
//PlaySound (TEXT ("D:\\音频文件\\1.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
}
break;
case ID_STOP:
{
PlaySound (NULL, NULL, SND_FILENAME);
}
break;
case ID_EXIT:
{
SendMessage (hWnd, WM_CLOSE, 0, 0);
}
break;
}
}
break;
}
}
break;
case WM_PAINT:
{
hDc = BeginPaint (hWnd, &ps);

EndPaint (hWnd, &ps);
}
break;
case WM_CLOSE:
{
PostQuitMessage (0);
}
break;
case WM_DESTROY:
{
DestroyWindow (hWnd);
}
break;
default:
return DefWindowProc (hWnd, message, wParam, lParam);
}

return 0;
}
追问
这能用单片机实现吗
追答
不行吧,这个好像用的windows的api做到的
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
scgwess
2011-03-05 · TA获得超过304个赞
知道答主
回答量:224
采纳率:0%
帮助的人:160万
展开全部
应该有帮助的 留个邮箱或者联系方式吧
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
陈兴爱渝
2011-03-01 · TA获得超过306个赞
知道答主
回答量:191
采纳率:0%
帮助的人:160万
展开全部
下面的代码是什么啊?我复制到我的VC6.0怎么不能用呢?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式