Sound in a program

Jblake00

Regular
Joined
Sep 27, 2003
Messages
76
Hi my Guru friends. I am curiuos on this one.
Maybe someone can tell me how to do this.. This my own little project. I am making a christmas tree to send my freinds and family for the holidays. So far I made a tree in PSP useing the picture tube of little pine trees to make a bigger one. Doesn't look bad either if I must say so myself. However I still am a little disapointed about my lights. Some of them still look square even after making a very small image in paint with the picture tube pines, then I put painted round dots in the center of them. My original idea was to use a graphic method to draw small round lights. However I can't figure out how to fill them inside of the main Picture box. But I can fill a circle that is on a blank form.
Anyway here is what is really eating at me. I want to know how to may the form play a sound file of some type. Maybe Jingle bells.
Also I want the sound to play after the button is clicked. Also it should loop or play over and over untill the app is closed. Hey if I could get it to snow I could do
"I am Dreaming of a White Christimas"..That would be awesome.
I will go ahead and post my code, try not to laught to hard..
Btw if someone could please tell me how to fill my circles....
Visual Basic:
    Inherits System.Windows.Forms.Form

#End Region
    Dim bulb(47) As PictureBox
    Dim bulbs(78) As PictureBox
    Dim bulbes(113) As PictureBox
    Dim face(10) As AccessibleStates
    Dim a As Integer
    Dim b As Integer
    Dim c As Integer
    Private Sub btnLights_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLights.Click
        Timer1.Enabled = True
        Timer2.Enabled = True
        Timer3.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        bulb(1) = PictureBox1
        bulb(2) = PictureBox2
        bulb(3) = PictureBox3
        bulb(4) = PictureBox4
        bulb(5) = PictureBox5
        bulb(6) = PictureBox6
        bulb(7) = PictureBox7
        bulb(8) = PictureBox8
        bulb(9) = PictureBox9
        bulb(10) = PictureBox10
        bulb(11) = PictureBox11
        bulb(12) = PictureBox12
        bulb(13) = PictureBox13
        bulb(14) = PictureBox14
        bulb(15) = PictureBox15
        bulb(16) = PictureBox16
        bulb(17) = PictureBox17
        bulb(18) = PictureBox18
        bulb(19) = PictureBox19
        bulb(20) = PictureBox20
        bulb(21) = PictureBox21
        bulb(22) = PictureBox22
        bulb(23) = PictureBox23
        bulb(24) = PictureBox24
        bulb(25) = PictureBox25
        bulb(26) = PictureBox26
        bulb(27) = PictureBox27
        bulb(28) = PictureBox28
        bulb(29) = PictureBox29
        bulb(30) = PictureBox30
        bulb(31) = PictureBox31
        bulb(32) = PictureBox32
        bulb(33) = PictureBox33
        bulb(34) = PictureBox34
        bulb(35) = PictureBox35
        bulb(36) = PictureBox36
        bulb(37) = PictureBox37
        bulb(38) = PictureBox38
        bulb(39) = PictureBox39
        bulb(40) = PictureBox40
        bulb(41) = PictureBox41
        bulb(42) = PictureBox42
        bulb(43) = PictureBox43
        bulb(44) = PictureBox44
        bulb(45) = PictureBox45
        bulb(46) = PictureBox46
        bulb(47) = PictureBox47
        For a = 1 To 47
            bulb(a).Visible = Not bulb(a).Visible
        Next 
 'My first intintional bug, it creates a blured face
'it's kinda cool...
        lblFace.Location = New System.Drawing.Point(40, 56)
        lblFace.Location = New System.Drawing.Point(50, 56)
        lblFace.Location = New System.Drawing.Point(60, 56)
        lblFace.Location = New System.Drawing.Point(70, 56)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 167, 34, 7, 7)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 162, 37, 7, 7)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 157, 40, 7, 7)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 152, 41, 7, 7)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 147, 42, 7, 7)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 142, 44, 7, 7)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 137, 46, 7, 7)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 132, 48, 7, 7)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 127, 50, 7, 7)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 122, 48, 7, 7)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 117, 46, 7, 7)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 112, 47, 7, 7)
        mainPicBox.CreateGraphics.DrawEllipse(Pens.Gold, 105, 46, 7, 7)
        Dim path As New Drawing2D.GraphicsPath()
        path.AddEllipse(2, 7, 7, 7)      
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load     
    End Sub 
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick      
        bulbs(48) = PictureBox48
        bulbs(49) = PictureBox49
        bulbs(50) = PictureBox50
        bulbs(51) = PictureBox51
        bulbs(52) = PictureBox52
        bulbs(53) = PictureBox53
        bulbs(54) = PictureBox54
        bulbs(55) = PictureBox55
        bulbs(56) = PictureBox56
        bulbs(57) = PictureBox57
        bulbs(58) = PictureBox58
        bulbs(59) = PictureBox59
        bulbs(60) = PictureBox60
        bulbs(61) = PictureBox61
        bulbs(62) = PictureBox62
        bulbs(63) = PictureBox63
        bulbs(64) = PictureBox64
        bulbs(65) = PictureBox65
        bulbs(66) = PictureBox66
        bulbs(67) = PictureBox67
        bulbs(68) = PictureBox68
        bulbs(69) = PictureBox69
        bulbs(70) = PictureBox70
        bulbs(71) = PictureBox71
        bulbs(72) = PictureBox72
        bulbs(73) = PictureBox73
        bulbs(74) = PictureBox74
        bulbs(75) = PictureBox75
        bulbs(76) = PictureBox76
        bulbs(77) = PictureBox77
        bulbs(78) = PictureBox78
        For b = 48 To 78
            bulbs(b).Visible = Not bulbs(b).Visible
        Next
        lblFace.Location = New System.Drawing.Point(70, 56)
        lblFace.Location = New System.Drawing.Point(70, 58)
        lblFace.Location = New System.Drawing.Point(70, 60)
        lblFace.Location = New System.Drawing.Point(70, 62)
    End Sub
    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        bulbes(79) = PictureBox79
        bulbes(80) = PictureBox80
        bulbes(81) = PictureBox81
        bulbes(82) = PictureBox82
        bulbes(83) = PictureBox83
        bulbes(84) = PictureBox84
        bulbes(85) = PictureBox85
        bulbes(86) = PictureBox86
        bulbes(87) = PictureBox87
        bulbes(88) = PictureBox88
        bulbes(89) = PictureBox89
        bulbes(90) = PictureBox90
        bulbes(91) = PictureBox91
        bulbes(92) = PictureBox92
        bulbes(93) = PictureBox93
        bulbes(94) = PictureBox94
        bulbes(95) = PictureBox95
        bulbes(96) = PictureBox96
        bulbes(97) = PictureBox97
        bulbes(98) = PictureBox98
        bulbes(99) = PictureBox99
        bulbes(100) = PictureBox100
        bulbes(101) = PictureBox101
        bulbes(102) = PictureBox102
        bulbes(103) = PictureBox103
        bulbes(104) = PictureBox104
        bulbes(105) = PictureBox105
        bulbes(106) = PictureBox106
        bulbes(107) = PictureBox107
        bulbes(108) = PictureBox108
        bulbes(109) = PictureBox109
        bulbes(110) = PictureBox110
        bulbes(111) = PictureBox111
        bulbes(112) = PictureBox112
        bulbes(113) = PictureBox113
        For c = 79 To 113
            bulbes(c).Visible = Not bulbes(c).Visible
        Next
    End Sub
    Private Sub mainPicBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mainPicBox.Click
    End Sub
    Private Sub mainPicBox_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles mainPicBox.Paint
    End Sub
'this code will be removed. It was an expirement to fill an pentigon.
'But I expected it to show up on top of the picture box, But instead it ended up on top of the form but under the main picture box.
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim myPoints() As Point = {New Point(10, 30), New Point(100, 10), New Point(150, 75), New Point(100, 150), New Point(10, 130)}
        e.Graphics.DrawPolygon(Pens.Blue, myPoints)
        Dim i As Integer
        Dim myPen As Pen
        For i = 0 To myPoints.Length - 2
            If (i Mod 2) = 0 Then
                myPen = Pens.Red
            Else
                myPen = Pens.Blue
            End If
            e.Graphics.DrawLine(myPen, myPoints(i), myPoints(i + 1))
            e.Graphics.FillPolygon(Brushes.Green, myPoints)
        Next
    End Sub
End Class
 
Wow I justed posted this and then I when to www.vbexplorer.com and found out this.
Visual Basic:
Sub PlayWav(SoundName As String)
  Dim tmpSoundName As String
  Dim wFlags%, X%
  
  ' declare statements (Place in a bas module.)
  ''**********************************
  '#If Win32 Then
  'Public Declare Function sndPlaySound& Lib "winmm.dll" Alias
"sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long)
  '#Else
  'Public Declare Function sndPlaySound% Lib "mmsystem.dll" (ByVal
lpszSoundName As String, ByVal uFlags As Integer)
  '#End If 'WIN32
  ' **********************************
  ' WAV Sound values
  'Global Const SND_SYNC = &H0

  'Global Const SND_ASYNC = &H1

  'Global Const SND_NODEFAULT = &H2

  'Global Const SND_LOOP = &H8

  'Global Const SND_NOSTOP = &H10

  ' **********************************
  
  ' *** pathWavFiles is a var with the subDir where
  '     the sound files are stored
  tmpSoundName = pathWavFiles & SoundName
  
  wFlags% = SND_ASYNC Or SND_NODEFAULT
  X% = sndPlaySound(tmpSoundName, wFlags%)
 
End Sub
 
Back
Top