How to play a sound in MFC?

This is a discussion on How to play a sound in MFC? within the Windows Programming forums, part of the Platform Specific Boards category; Greetings. May I know how can I play a sound file, "Hello.WAV" in MFC? Some notes that I taken down ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    6

    Question How to play a sound in MFC?

    Greetings.

    May I know how can I play a sound file, "Hello.WAV" in MFC?

    Some notes that I taken down in the past:
    "
    Project | Settings | Link | Object/Library modules: | winmm.lib
    #include "winmm.h"
    PlaySound("hello.wav",NULL,SND_FILENAME);
    "

    However, it did not work, error message is winmm.h is not found.

    May I know what I have left out?
    Advanced thanks.

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    The header file is <mmsystem.h>.
    zen

  3. #3
    Sh0cky
    Guest
    Hi,
    I was wondering if you could tell me how to do this :

    I want to import a midi file to the program, so that when the person opens the program... the midi plays.


    Thanks

  4. #4
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You could try this -

    Code:
    Function: PlayMidi() // // Purpose: Plays a midi file 
    
    BOOL PlayMidi(char *sFileName)
     {    
     char buf[256];
          sprintf(buf, "open %s type sequencer alias MUSIC", sFileName);
         if (mciSendString("close all", NULL, 0, NULL) != 0)
         return(FALSE);     }
    
          if (mciSendString(buf, NULL, 0, NULL) != 0)  
       return(FALSE); 
    
         if (mciSendString("play MUSIC from 0", NULL, 0, g_hWnd) != 0)    
     return(FALSE);  
    
       // Yahoo!   
      return TRUE;
     }
    I couldn't find it on the latest MSDN (it was on an older version), and haven't tried it so don't know it it works but you could try calling it from your WM_CREATE message handler.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX Question
    By bladerunner627 in forum Game Programming
    Replies: 2
    Last Post: 04-04-2005, 11:55 AM
  2. Low latency sound effects
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 12-21-2004, 12:58 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 11:38 AM
  4. sounds?
    By BODYBUILDNERD in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2002, 02:34 PM
  5. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM

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