Results 1 to 5 of 5

Thread: Question in C++ programming (Using .WAV files)

  1. #1
    Silver Member Linedawg's Avatar
    Join Date
    Sep 2005
    Posts
    308

    Question Question in C++ programming (Using .WAV files)

    Hello guys, I have a stupid question. I was programming a GUI menu screen after I got every thing working I decided to place a wave file to run in the back ground to add more depth to my application. But I realized I have no clue on how to trigger a sound file. Dose any one knows how to write a function, class or even a header file to allow for sounds? Also can I use C++ to active and search for the default soundcard on any windows system or do I have to use direct X?

    I try to add this to my main with in the code:

    Public Class SoundClass
    Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
    As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer
    ' name specifies the sound file when the SND_FILENAME flag is set.
    ' hmod specifies an executable file handle.
    ' hmod must be Nothing if the SND_RESOURCE flag is not set.
    ' flags specifies which flags are set.

    ' The PlaySound documentation lists all valid flags.
    Public Const SND_MEMORY = &H4 'play stream
    Public Const SND_NOSTOP = &H10 ' no stop
    Public Const SND_SYNC = &H0 ' play synchronously
    Public Const SND_ASYNC = &H1 ' play asynchronously
    Public Const SND_PURGE = &H100 ' purge non-static event for task
    Public Const SND_LOOP = &H8 ' loop
    Public Const SND_NODEFAULT = &H2 ' silence if no file
    Public Const SND_FILENAME = &H20000 ' name is file name
    Public Const SND_RESOURCE = &H40004 ' name is resource name or atom

    Public Sub PlaySoundStream(ByVal filename As String)
    ' Plays a sound from filename.
    PlaySound(filename, Nothing, SND_MEMORY Or SND_ASYNC Or SND_LOOP)
    End Sub

    Public Sub PlaySoundFile(ByVal filename As String)
    ' Plays a sound from filename.
    PlaySound(filename, Nothing, SND_FILENAME Or SND_ASYNC Or SND_LOOP)
    End Sub
    Public Sub StopSound()
    ' Plays a sound from filename.
    PlaySound(Nothing, Nothing, SND_NODEFAULT Or SND_FILENAME)
    End Sub

    End Class


    But I had no luck with it, I feel as if Iím missing some thing. So dose any one out there knows of a simple way to trigger a .WAV file to run in the back ground of my menu screen? Also dose any one know how to trigger a sound when you move a mouse curser over a button?

    This has been driving my crazy for the past few days. I cant believe I have never tried this before lol but Iím stuck.

  2. #2
    Security Intelligence TZ Veteran cash_site's Avatar
    Join Date
    Jul 2002
    Location
    Software Paradise
    Posts
    3,735
    I remember trying to make some code in MFC c++.

    The initial class setup was something similar to what you posted...

    I've found some other links on MSDN library

    http://msdn.microsoft.com/archive/de...oundsample.asp

    They have some samples at bottom too...

    Also, another thread with similar question.
    http://forums.microsoft.com/MSDN/Sho...02802&SiteID=1

    This is the search from MSDN results
    http://search.msdn.microsoft.com/sea...av+c%2b%2b

    --- 0wN3D by 3gG ---

  3. #3
    Silver Member Linedawg's Avatar
    Join Date
    Sep 2005
    Posts
    308
    Thanks Cash_site,
    The links you posted where exactly what I was looking for. I canít believe I have over looked it when searching MSND. Thanks for the awesome links.

  4. #4
    Silver Member Linedawg's Avatar
    Join Date
    Sep 2005
    Posts
    308
    Also to address my Direct X question I found this link that has a pretty good tutorial on how to get started.
    http://www.c-unit.com/tutorials/directx/?t=23

    Just wanted to add this link into the tread so if any one else with the question can have a tutorial.

  5. #5
    Security Intelligence TZ Veteran cash_site's Avatar
    Join Date
    Jul 2002
    Location
    Software Paradise
    Posts
    3,735
    Good to hear LineDawg! You are getting pretty good at this software stuff, you'll have to post some links to your programs

    --- 0wN3D by 3gG ---

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •