CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Oct 2011

    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:

    #include <windows.h>
    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
        while(GetMessage(&msg, NULL, 0, 0))
        return msg.wParam;
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
            HDC                    hdc;
            PAINTSTRUCT            ps;
            RECT                   rect;
                  //////////////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:
                       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

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

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.