DialogWindow Not Making sounds......

This is a discussion on DialogWindow Not Making sounds...... within the Windows Programming forums, part of the Platform Specific Boards category; Shoudln't this window make sounds when I press the VK_UP button? Code: BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message, WPARAM ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    DialogWindow Not Making sounds......

    Shoudln't this window make sounds when I press the VK_UP button?

    Code:
    
    BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message, 
                                WPARAM wParam, LPARAM lParam)
    {
         switch (message)
         {
         case WM_INITDIALOG :
    
    		return TRUE ;
    
    
    	  case WM_KEYDOWN:
    		  
    		  {
    	
    			  switch (wParam)
    
    			{	
    
    				case VK_UP:
    
    				 PlaySound (TEXT ("puma.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
    
    
    
    				 break;
    
    
    			 }
    
    
    			
    	}
              
         case WM_COMMAND :
              switch (LOWORD (wParam))
              {
              case IDOK :
              case IDCANCEL :
                   EndDialog (hDlg, 0) ;
                   return TRUE ;
              }
              break ;
         }
         return FALSE ;
    }
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    Have you tested to see if execution actually flows to the VK_UP case?

    Here's a couple of ideas:

    1) Try using the sndPlaySound API call instead of PlaySound

    2) Instead of "break;" after your PlaySound function, use "return 0;"

    Give those a try.

    I'm sure someone else can come up with something better, but I hope that helps.

    -Dan

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    make sure the path is correct, use a break point and GetLastError()

    use a char array for the filename not a constant.

    ie
    if(! PlaySound(......) )
    iError=GetLastError();

    ".\\puma.wav" to load a sound from the current directory

    "c:\\thisFolder\\puma.wav"

    or look at GetCurrentDirectory() and sprintf() to format your own string no matter where the app is running.

    use

    PlaySound(NULL,NULL,SND_FILENAME | SND_ASYNC) ;//stop current sound if one playing
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    The following code will create a full path to a sound file in your exe file's directory.

    sound_filename is the filename you wish to add the path to
    sound_fullpath is the full path to the file

    i.e if sound_filename = "hello.wav" after running this code sound_fullpath will = "C:\directory\of\exe\hello.wav"

    Code:
    char sound_fullpath[MAX_PATH];
    char p[MAX_PATH],*q;
    
    GetModuleFileName(NULL,p,sizeof(p));
    q=p+strlen(p);
    while (q >= p && *q != '\\') q--;
    *(++q)=0;
    wsprintf(sound_fullpath,"%s%s",p,sound_filename);

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    GetCurrentDirectory(255,szWorkingDirectory);
    sprintf(szFilePath ,"%s\\%s ,szWorkingDirectory ,szFileName );

    or use

    SetCurrentDirectory()
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making control...
    By Finchie_88 in forum C++ Programming
    Replies: 2
    Last Post: 09-07-2004, 01:42 PM
  2. Making dll's in C???
    By frolicchap in forum C Programming
    Replies: 2
    Last Post: 02-03-2003, 04:15 AM
  3. Replies: 2
    Last Post: 01-13-2003, 12:28 PM
  4. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 07:37 AM
  5. Sounds, or no sounds?
    By face_master in forum C++ Programming
    Replies: 3
    Last Post: 09-03-2001, 05:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21