Help with PlaySound() on Windows 7!! Only BEEPS??
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Help with PlaySound() on Windows 7!! Only BEEPS??

  1. #1
    Join Date
    Oct 2011
    Posts
    2

    Unhappy 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 08:36 AM. Reason: Added code tags

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,062

    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.

  3. #3
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: Help with PlaySound() on Windows 7!! Only BEEPS??

    the actual API is sndplaysound

    get the usage here

    http://msdn.microsoft.com/en-us/library/aa909803.aspx

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,545

    Re: Help with PlaySound() on Windows 7!! Only BEEPS??

    Quote Originally Posted by aamir121a View Post
    the actual API is sndplaysound

    get the usage here

    http://msdn.microsoft.com/en-us/library/aa909803.aspx
    1. Your link points to a function used in WinCE, not Windows 7
    2. What is wrong in using PlaySound function?
      It works for me (although my App was build in old VC++ 6.0)
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center