在VC里面用PlaySound加入声音,编译成功却运行还是没有声音怎么办,急求!!!!!!!江湖救急

Jason_Lu_USA 2014-05-22 01:02:44
// GAME.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"
#include<stdio.h>
#include <mmsystem.h>
#pragma comment(lib, "WINMM.LIB")
#define MAX_LOADSTRING 100
struct BULLET
{
int x,y;
bool exist;
};
HBITMAP NPC[4],bg[3],bullet;
HDC hdc,mdc,bufdc;
HWND hWnd;
DWORD tPre,tNow;
int x0=0,x1=0,x2=0;
int num,dir,x,y;
int nowX,nowY,bcount;
int m=0;

bool archKeyStatus[4];
BULLET b[30];
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text

// Foward declarations of functions included in this code module:
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
void CartoonPaint(HDC hdc);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
PlaySound(TEXT("最炫名族风.m4r.wav"),NULL,SND_FILENAME|SND_SYNC|SND_LOOP);
MSG msg;
LoadString(hInstance, IDC_GAME2, szWindowClass, MAX_LOADSTRING);
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_GAME2);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_GAME2;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
if(!RegisterClassEx(&wcex))return 0;
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
// Main message loop:
while (msg.message!=WM_QUIT)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
tNow=GetTickCount();
if(tNow-tPre>=40)
CartoonPaint(hdc);
}
}

return msg.wParam;
}



//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
HBITMAP bmp;
POINT pt,lt,rb;
RECT rect;
hInst=hInstance;
hWnd = CreateWindow(szWindowClass,"GAME2(Jason)", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if(!hWnd)return FALSE;
MoveWindow(hWnd,10,10,640,480,true);
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
hdc=GetDC(hWnd);
mdc=CreateCompatibleDC(hdc);
bufdc=CreateCompatibleDC(hdc);
bmp=CreateCompatibleBitmap(hdc,640,480);
SelectObject(mdc,bmp);
x=300;
y=250;
dir=0;
num=0;
NPC[0]=(HBITMAP)LoadImage(NULL,"NPC1.bmp",IMAGE_BITMAP,440,148,LR_LOADFROMFILE);
NPC[1]=(HBITMAP)LoadImage(NULL,"NPC2.bmp",IMAGE_BITMAP,424,154,LR_LOADFROMFILE);
NPC[2]=(HBITMAP)LoadImage(NULL,"NPC3.bmp",IMAGE_BITMAP,480,148,LR_LOADFROMFILE);
NPC[3]=(HBITMAP)LoadImage(NULL,"NPC4.bmp",IMAGE_BITMAP,480,148,LR_LOADFROMFILE);
bg[0]=(HBITMAP)LoadImage(NULL,"bg0.bmp",IMAGE_BITMAP,640,480,LR_LOADFROMFILE);
bg[1]=(HBITMAP)LoadImage(NULL,"bg1.bmp",IMAGE_BITMAP,640,600,LR_LOADFROMFILE);
bg[2]=(HBITMAP)LoadImage(NULL,"bg2.bmp",IMAGE_BITMAP,640,600,LR_LOADFROMFILE);
bullet=(HBITMAP)LoadImage(NULL,"bullet.bmp",IMAGE_BITMAP,10,10,LR_LOADFROMFILE);
nowX=300;
nowY=300;
pt.x=300;
pt.y=300;
ClientToScreen(hWnd,&pt);
SetCursorPos(pt.x,pt.y);
ShowCursor(true);
lt.x=rect.left;
lt.y=rect.top;
rb.x=rect.right;
rb.y=rect.bottom;
ClientToScreen(hWnd,<);
ClientToScreen(hWnd,&rb);
rect.left=lt.x;
rect.top=lt.y;
rect.right=rb.x;
rect.bottom=rb.y;
ClipCursor(&rect);
CartoonPaint(hdc);
return TRUE;
}
void CartoonPaint(HDC hdc)
{
int i;
char str[20]="";
int w,h;
if(nowX<x)
{
nowX+=10;
if(nowX>x) nowX=x;
}
else
{
nowX-=10;
if(nowX<x) nowX=x;
}
if(nowY<y)
{
nowY+=10;
if(nowY>y) nowY=y;
}
else
{
nowY-=10;
if(nowY<y) nowY=y;
}
SelectObject(bufdc,bg[0]);
BitBlt(mdc,0,0,x0,300,bufdc,640-x0,0,SRCCOPY);
BitBlt(mdc,x0,0,640-x0,300,bufdc,0,0,SRCCOPY);
BitBlt(mdc,0,300,x2,180,bufdc,640-x2,300,SRCCOPY);
BitBlt(mdc,x2,300,640-x2,180,bufdc,0,300,SRCCOPY);
SelectObject(bufdc,bg[1]);
BitBlt(mdc,0,0,x1,300,bufdc,640-x1,300,SRCAND);
BitBlt(mdc,x1,0,640-x1,300,bufdc,0,300,SRCAND);
BitBlt(mdc,0,0,x1,300,bufdc,640-x1,0,SRCPAINT);
BitBlt(mdc,x1,0,640-x1,300,bufdc,0,0,SRCPAINT);
SelectObject(bufdc,bg[2]);
BitBlt(mdc,0,250,x2,300,bufdc,640-x2,300,SRCAND);
BitBlt(mdc,x2,250,640-x2,300,bufdc,0,300,SRCAND);
BitBlt(mdc,0,250,x2,300,bufdc,640-x2,0,SRCPAINT);
BitBlt(mdc,x2,250,640-x2,300,bufdc,0,0,SRCPAINT);
SelectObject(bufdc,NPC[dir]);
switch(dir)
{
case 0:
w=55;
h=74;
break;
case 1:
w=53;
h=77;
break;
case 2:
w=60;
h=74;
break;
case 3:
w=60;
h=74;
break;
}
BitBlt(mdc,x,y,w,h,bufdc,num*w,h,SRCAND);
BitBlt(mdc,x,y,w,h,bufdc,num*w,0,SRCPAINT);
SelectObject(bufdc,bullet);
if(bcount!=0)
for(i=0;i<30;i++)
if(b[i].exist)
{//贴子弹 s

BitBlt(mdc,b[i].x,b[i].y,10,10,bufdc,0,10,SRCAND);
BitBlt(mdc,b[i].x,b[i].y,10,10,bufdc,0,0,SRCPAINT);
b[i].x-=10;
if(b[i].x<0)
{
bcount--;
b[i].exist=false;
}
}
BitBlt(hdc,0,0,640,480,mdc,0,0,SRCCOPY);
tPre=GetTickCount();
x0+=2;
if(x0==640) x0=0;
x1+=5;
if(x1==640) x1=0;
x2+=8;
if(x2==640) x2=0;
num++;
if(num==8)
num=0;
}

//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int i;
switch (message)
{

case WM_KEYDOWN://按下按键
switch (wParam)
{
case VK_ESCAPE://exit
PostQuitMessage(0);
break;
case VK_UP://up
switch(dir)
{
case 0:
y-=10;
break;
case 1:
x-=1;
y-=8;
break;
case 2:
x+=2;
y-=10;
break;
case 3:
x+=2;
y-=10;
break;
}
if(y<0)
y=0;
dir=0;
break;
case VK_DOWN://down
switch(dir)
{
case 0:
x+=1;
y+=8;
break;
case 1:
y+=10;
break;
case 2:
x+=3;
y+=6;
break;
case 3:
x+=3;
y+=6;
break;
}
if(y>375)
y=375;
dir=1;
break;
case VK_LEFT://left
switch(dir)
{
case 0:
x-=12;
break;
case 1:
x-=13;
y+=4;
break;
case 2:
x-=10;
break;
case 3:
x-=10;
break;
}
if(x<0)
x=0;
dir=2;
break;
case VK_RIGHT://right
switch(dir)
{
case 0:
x+=8;
break;
case 1:
x+=7;
y+=4;
break;
case 2:
x+=10;
break;
case 3:
x+=10;
break;
}
if(x>575)
x=575;
dir=3;
break;
}
break;
case WM_MOUSEMOVE:
x=LOWORD(lParam);
if(x>530)
x=530;
else if(x<0)
x=0;
y=HIWORD(lParam);
if(y>380)
y=380;
else if(y<0)
y=0;
break;
case WM_LBUTTONDOWN:
for(i=0;i<30;i++)
{
if(!b[i].exist)
{
b[i].x=nowX;
b[i].y=nowY+30;
b[i].exist=true;
bcount++;
break;
}
}
break;
case WM_DESTROY:
ClipCursor(NULL);
int i;
DeleteDC(mdc);
DeleteDC(bufdc);
for(i=0;i<4;i++)
DeleteObject(NPC[i]);
DeleteObject(bg[0]);
DeleteObject(bg[1]);
DeleteObject(bg[2]);
DeleteObject(bullet);
ReleaseDC(hWnd,hdc);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

代码如上,编译成功了,但就是没有声音,哎,兄弟们帮个忙吧!!!
...全文
318 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-05-22
  • 打赏
  • 举报
回复
先确认用Media Player随便播放一段wav能听到声音 然后判断PlaySound函数的返回值。 GetLastError();
Jason_Lu_USA 2014-05-22
  • 打赏
  • 举报
回复
对不起哦,我是新人,刚刚学这个,还不太懂
FightForProgrammer 2014-05-22
  • 打赏
  • 举报
回复
有没有点职业素养??就这么贴个代码还不用标准格式?试想一下你看人家的帖子看着这个排版还有心思看下去么

3,882

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧