此程序原本未能完成调用声音文件的预期结果,
错误原因如下:error LNK2019: 无法解析的外部符号 __imp__PlaySoundW@12,该符号在函数 "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 中被引用,
经过学长的帮助 在程序中加入了#pragma comment(lib, "WINMM.LIB") 圆满解决了此问题
/*
* 程序输出:“在应用程序窗口输出 hello win8!”
*/
/* HELLOWIN.C -- Displays(显示) * hello,windows 8 * in client(客户端) area 在客户端区域上 显示hello,windows 8 */ # include<windows.h>
#pragma comment(lib, "WINMM.LIB")
LRESULT CALLBACK WndProc (HWND ,UINT,WPARAM,LPARAM) ; //UINT 表示unsigned int. 这句是窗口过程的声明 int WINAPI WinMain (HINSTANCE hInstance ,HINSTANCE hPrevInstance ,PSTR szCmdLine , int iCmdShow) //PSTR 是指向非宽字符串的指针 { static TCHAR szAppname [] = TEXT ("HELLOWIN"); HWND hwnd ; MSG msg;//消息结构 WNDCLASS wndclass ;//窗口类结构 wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ;//这是WndProc的引用吗? wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance ; //实例句柄 wndclass.hIcon = LoadIcon (NULL,IDI_APPLICATION) ; //设定目标 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); //预定义的鼠标指针 wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; //白色画刷 指定系统色 wndclass.lpszMenuName = NULL ; //菜单窗口类名称 wndclass.lpszClassName = szAppname ; // if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("这是啥"),szAppname ,MB_ICONERROR) ; return 0; } hwnd = CreateWindow (szAppname , //hwnd 是句柄 ,szappname是窗口类名称 TEXT ("大家好 才是真的好"), //窗口标题 WS_OVERLAPPEDWINDOW, //窗口风格(窗口格式) CW_USEDEFAULT, //初始x坐标 CW_USEDEFAULT, //初始y坐标 CW_USEDEFAULT, //初始x方向尺寸 CW_USEDEFAULT, //初始y方向尺寸 NULL, //父窗口句柄 NULL, //窗口菜单句柄 hInstance , //程序实例句柄 NULL); //创建参数 ShowWindow (hwnd ,iCmdShow) ; UpdateWindow (hwnd ) ; while (GetMessage (&msg , NULL,0,0)) //消息循环 { TranslateMessage (&msg); DispatchMessage (&msg) ; } return msg.wParam ; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; //绘制结构 RECT rect ;//矩形结构 switch (message) { case WM_CREATE: //声音文件怎么才能读取 求解释!! PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, TEXT ("Hello, Windows 8!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
/*
运行结果: