读书人

新手请教为什么找不到PlaySound啊

发布时间: 2012-01-14 20:02:35 作者: rapoo

新手请问为什么找不到PlaySound啊?
我有在project-> setting里面加上了WINMM.LIB,程序也有#pragma comment(lib, "winmm.lib ")为什么还是会报错说PlaySound没有声明

F:\C++专题\C++源代码\Main\main.cpp(88) : error C2065: 'PlaySound ' : undeclared identifier
F:\C++专题\C++源代码\Main\main.cpp(88) : error C2065: 'SND_FILENAME ' : undeclared identifier
F:\C++专题\C++源代码\Main\main.cpp(88) : error C2065: 'SND_SYNC ' : undeclared identifier
Error executing cl.exe.


#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <math.h>
#include "resource.h "

#pragma comment(lib, "d3dx9d.lib ")
#pragma comment(lib, "d3dx10.lib ")
#pragma comment(lib, "d3dx10d.lib ")
#pragma comment(lib, "d3dxof.lib ")
#pragma comment(lib, "ddraw.lib ")
#pragma comment(lib, "WINMM.lib ")

#define WINDOW_CLASS_NAME1 "WNDCLASS1 "
//#define WINDOW_CLASS_NAME2 "WNDCLASS2 "
HINSTANCE MAIN_HINSTANCE;

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

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wndclass1;
//WNDLCASSEX wndclass2;
HWND hwnd1;
MSG msg;

wndclass1.cbSize = sizeof(WNDCLASSEX);
wndclass1.cbClsExtra = 0;
wndclass1.cbWndExtra = 0;
wndclass1.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass1.hCursor = LoadCursor(hInstance,MAKEINTRESOURCE(IDC_CURSOR1));
wndclass1.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
wndclass1.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
wndclass1.hInstance = hInstance;
wndclass1.lpfnWndProc = WndProc;
wndclass1.lpszClassName = WINDOW_CLASS_NAME1;
wndclass1.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wndclass1.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;

if(!RegisterClassEx(&wndclass1))
{
MessageBox(NULL, "This program requires WindowsNT! ", "NT ERROR ", MB_OK | MB_ICONEXCLAMATION);
return (0);
}

if(!(hwnd1 = CreateWindowEx(NULL,
WINDOW_CLASS_NAME1,
"First Window ",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL)))
return (0);

MAIN_HINSTANCE = hInstance;

while(true)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (msg.wParam);
}



LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(message)
{
case WM_CREATE:
{
PlaySound( "begin.wav ", MAIN_HINSTANCE, SND_FILENAME | SND_SYNC);
return 0;
}
break;
/*case WM_COMMAND:
{
switch(LOWORD(wparam))
{
case ID_MENUITEM_Shaman:
{*/

case WM_PAINT:
{
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
break;

default:
break;
}

return DefWindowProc(hwnd, message, wparam, lparam);
}






[解决办法]
PlaySound恐怕不是MFC里边的吧,应该是头文件没包含进去吧
它在mmsystem.h文件声明
[解决办法]

PlaySound()

是 Win32 API 函数,跟 MFC 没有关系。

下面是 MSDN 中关于 PlaySound() 函数的说明:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_playsound.asp

读书人网 >VC/MFC

热点推荐