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...
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.
Re: Help with PlaySound() on Windows 7!! Only BEEPS??
Re: Help with PlaySound() on Windows 7!! Only BEEPS??
Quote:
Originally Posted by
aamir121a
- Your link points to a function used in WinCE, not Windows 7
- What is wrong in using PlaySound function? :confused:
It works for me (although my App was build in old VC++ 6.0) :cool: