Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

splash screen sound 1

Status
Not open for further replies.

hackproof

Programmer
Feb 29, 2004
41
PH
Hi guys,

I wanted to play a sound when my splash screen appears but I don't know how in VB .Net. I used to add an ole object in my form to plays sounds in VB6 but I dont see that object anymore in VB .Net. Could anyone help me on this?
 
Code:
Private Declare Auto Function PlaySound Lib "winmm.dll" _
    (ByVal lpszSoundName As String, ByVal hModule As Integer, _
     ByVal dwFlags As Integer) As Integer

Private Const SND_FILENAME As Integer = &H20000

Public sub PlayWav(ByVal fileFullPath As String)
  Dim iRet As Integer = 0
  Try
    iRet = PlaySound(fileFullPath, 0, SND_FILENAME)
  Catch
  End Try
End Function

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Use this class:
Code:
Public Class Sound
    Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
      As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer

    Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
      As Byte(), ByVal hmod As Integer, ByVal flags As Integer) As Integer

    Public Const SND_SYNC = &H0 [COLOR=green]' play synchronously [/color]
    Public Const SND_ASYNC = &H1 [COLOR=green]' play asynchronously [/color]
    Public Const SND_MEMORY = &H4  [COLOR=green]'Play wav in memory[/color]
    Public Const SND_ALIAS = &H10000 [COLOR=green]'Play system alias wav [/color]
    Public Const SND_NODEFAULT = &H2
    Public Const SND_FILENAME = &H20000 [COLOR=green]' name is file name [/color]
    Public Const SND_RESOURCE = &H40004 [COLOR=green]' name is resource name or atom [/color]
    ...
End Class

Using the code:

Code:
    Private Sub btnFile_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnFile.Click
        [COLOR=green]'File Located in executable dir, change it if you need[/color]
        Sound.PlayWaveFile("sn01088a.wav")
    End Sub

    Private Sub btnEmbed_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnEmbed.Click
        [COLOR=green]'Remeber to include the wave in the project 
        'and then in the "build action"
        'properties set it as: "Embedded Resource"[/color]
        Sound.PlayWaveResource("The Microsoft Sound.wav")
    End Sub

    Private Sub btnSystem_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnSystem.Click

[COLOR=green]        'Here some ...

        '"SystemQuestion"
        '"SystemExclaimation"
        '"SystemHand"
        '"Maximize"
        '"MenuCommand"
        '"MenuPopup"
        '"Minimize"
        '"MailBeep"
        '"Open"
        '"Close"
        '"SystemAsterisk"
        '"RestoreUp"
        '"RestoreDown"
        '"SystemExit"
        '"SystemStart"[/color]

        Sound.PlayWaveSystem("SystemExit")
    End Sub

Maybe this world is another planet’s Hell.
 
Thanks guys for the help. Do you know some other way to do this without using API? Just use the components that VB .Net already have?
 
Thanks guys, I was finally able to play audio files in VB .Net without using API. If you guys are curious about it, here is the code......

My.Computer.Audio.Play(My.Resources.Intro, AudioPlayMode.Background)

where "My.Resources.Intro" is the audio the I wanted to play which is already added in my resources file and "AudioPlayMode.Background" is the play mode of the file being played.
 
My.Computer.Audio.Play(My.Resources.Intro, AudioPlayMode.Background)
That's from version 2.0 of the .NET framework which is still in beta. You can't use that in version 1.1.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ahh dang..

I thought it worth a star (still is, but I wanted it on a 1.1 app), but then read the bit about 2.0

Well still nice. Now I just have one more reason to start porting everything to 2.0

:(


Rob
 
Yeah...the "My.Computer" class in 2.0 contains some very handy functions that were missing from 1.1


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top