-
October 2nd, 2011, 05:15 PM
#1
Help with PlaySound() on Windows 7!! Only BEEPS??
Help me out here? I'm following along with Programming Windows and it's been good to me so far but I was testing some stuff, went back to playing sounds, and realized that the PlaySound() function runs without errors but as soon as the program opens and it's supposed to play it just goes "Ding" or "Click" you know? Here's the code:
Code:
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("HelloWin");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
int xsSize = GetSystemMetrics(SM_CXSCREEN);
int ysSize = GetSystemMetrics(SM_CYSCREEN);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = 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);//Brushes could be: BLACK, DKGRAY, GRAY, LTGRAY, and NULL
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if(!RegisterClass (&wndclass))
{
MessageBox(NULL, TEXT("YOUR. COMPUTER. SUCKS."), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName, //class name
TEXT("The Hello Program"), //Caption
WS_OVERLAPPEDWINDOW, //Style
685, //x pos
0, //y pos
xsSize/2, //x size
ysSize-40, //y size
NULL, //parent window handle
NULL, //menu handle
hInstance, //instance handle
NULL) ; //creation parameters
ShowWindow(hwnd, iCmdShow); //SW_SHOWNORMAL right now, could be SW_SHOWMINNOACTIVE or SW_SHOWMAXIMIZED
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)
{
//////////////THE PROBLEM//////////////////
case WM_CREATE:
PlaySound(TEXT("Mosquito Tone.wav"), NULL, SND_FILENAME | SND_ASYNC);
return 0;
//////////////IS HERE//////////////////////////
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
DrawText(hdc, TEXT("Hello, Windows 7!"), -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);
}
Again, Windows 7 and my compiler is Dev C++ help me out PLEASE! I don't care if it's months from now...
Last edited by Marc G; October 3rd, 2011 at 07:36 AM.
Reason: Added code tags
-
October 3rd, 2011, 07:41 AM
#2
Re: Help with PlaySound() on Windows 7!! Only BEEPS??
Are you sure it can find the "Mosquito Tone.wav" file?
Maybe the current working directory is not correct?
To make sure, maybe you can try to specify a full path name in the PlaySound call.
-
October 4th, 2011, 11:21 PM
#3
Re: Help with PlaySound() on Windows 7!! Only BEEPS??
-
October 5th, 2011, 04:40 AM
#4
Re: Help with PlaySound() on Windows 7!! Only BEEPS??
Victor Nijegorodov
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|