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!

vb6 making a sound when mouse over command button? 1

Status
Not open for further replies.

jsundin3

Technical User
Oct 2, 2001
60
US
I was wondering how to include sound when someone puts their mouse over the button. Just wondering what is out there....looking for something like the forum to install like Norton 2003.
Thanks JeffS
 
Not the best but ..

Option Explicit
Private m_blnButtonOver As Boolean

Private Sub Command1_Click()

If Not m_blnButtonOver Then
'Play Sound
End If
m_blnButtonOver = True

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
m_blnButtonOver = False
End Sub
 
I tried to use the code above, for some reason I could not get any sound when I clicked or put my mouse over the command button. Was there something I was missing? I put command1 code in the COMMAND1.....

Any input would be appreciated JeffS
 
Try this

This goes in the Declarations section of your code

Option Explicit
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Const SND_ASYNC = &H1
Private Const SND_LOOP = &H8
Private Const SND_SYNC = &H0
Private SoundWasPlayed As Boolean

And here are the other procedures

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ret As Long

If SoundWasPlayed = False Then
ret = sndPlaySound("C:\windows\media\ding.wav", SND_ASYNC)
End If
SoundWasPlayed = True

End Sub


Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

SoundWasPlayed = False

End Sub
 
Excellent! Thank you.....Little things like this help keep me working with VB.....again works great!

JeffS
 
Is there a way I can still click on the COMMAND BUTTON and still play the sound (.wav)? This code beeps and then executes without clicking it...mouse going over it executes....any ideas?

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Shell "D:\JeffSCD\norton.bat", 1
Dim ret As Long

If SoundWasPlayed = False Then
ret = sndPlaySound("C:\windows\media\ding.wav", SND_ASYNC)
End If
SoundWasPlayed = True


End Sub

JeffS
 
If you want to play the sound when you click the button add this to your code.

Private Sub Command1_Click()
Dim ret As Long

ret = sndPlaySound("Put your sound here", SND_ASYNC)

End Sub

If you don't want to play the sound when you move over the button, just remove the code from

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

End Sub
 
Hey thanks, ClickHere (Programmer) worked kind of like how i wanted but putting the mouse it executed it if I clicked on it (not good), thank you I like knowing when I click on the button (with a sound).

Thanks again
JeffS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top