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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

play sound on startup of application

Status
Not open for further replies.

gnibbles

Programmer
Mar 15, 2000
79
0
0
CA
I'm just using a splash screen as my application startup and I just want to have a .wav file play when it opens.

gnibbles
nturpin@excite.com
 
Option Compare Database
Option Explicit

Public vid As Integer

Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Declare Function GetResSpec Lib "user32" _
Alias "GetDC" _
(ByVal hWnd As Long) As Long

Declare Function GetPixPerIn Lib "gdi32" _
Alias "GetDeviceCaps" _
(ByVal hDC As Long, _
ByVal nIndex As Long) As Long

Declare Function RelResSpec Lib "user32" _
Alias "ReleaseDC" _
(ByVal hWnd As Long, _
ByVal hDC As Long) As Long

Declare Function GetAVISize Lib "user32" _
Alias "GetClientRect" _
(ByVal hWnd As Long, lpRect As RECT) As Long

Declare Function AVIFunction Lib "winmm" _
Alias "mciSendStringA" _
(ByVal lpstrCommand As String, _
ByVal lpstrReturnStr As Any, _
ByVal wReturnLen As Long, _
ByVal hCallBack As Long) As Long

Declare Function GetAVIError Lib "winmm" _
Alias "mciGetErrorStringA" _
(ByVal dwError As Long, _
ByVal lpstrBuffer As String, _
ByVal uLength As Long) As Long


Sub PlayAVI(AVIFile As String, _
ScreenTop As Single, ScreenHeight As Single, _
ScreenLeft As Single, ScreenWidth As Single, _
Auto As Boolean)

Dim PixPerInX As Integer, PixPerInY As Integer
Dim CmdStr As String, TheError As String * 100
Dim TheAVIHwnd As String * 100
Dim AVISizeH As Long, AVISizeW As Long
Dim FRMHwnd As Long, hDC As Long
Dim TheAVIRect As RECT

On Error GoTo TheEnd

'Get the active form's window handle.
FRMHwnd = Screen.ActiveForm.hWnd

'Open the AVIVideo device with AVIFile
CmdStr = ("open " & AVIFile & _
" type AVIVideo alias TheVideo parent " & _
FRMHwnd & " style " & &H40000000)
vid = AVIFunction(CmdStr, 0&, 0, 0)

If vid <> 0 Then ' An error occurred.
vid = GetAVIError(vid, TheError, Len(TheError))
MsgBox TheError, vbOKOnly + vbCritical, &quot;AVI Error&quot;
GoTo TheEnd
End If

'Determine the .AVI Height and Width
vid = AVIFunction(&quot;status TheVideo window handle&quot;, TheAVIHwnd, Len(TheAVIHwnd), 0)
vid = GetAVISize(TheAVIHwnd, TheAVIRect)
AVISizeH = TheAVIRect.Bottom - TheAVIRect.Top
AVISizeW = TheAVIRect.Right - TheAVIRect.Left

'Retrieve pixels per inch
hDC = GetResSpec(FRMHwnd)
PixPerInX = GetPixPerIn(hDC, 88)
PixPerInY = GetPixPerIn(hDC, 90)
vid = RelResSpec(FRMHwnd, hDC)

If Auto = True Then

'Proportionally resize .AVI if necessary and center in display area.
If AVISizeW > ((ScreenWidth / 1440) * PixPerInY) Then
AVISizeH = (((ScreenWidth / 1440) * PixPerInY) / AVISizeW) * AVISizeH
AVISizeW = ((ScreenWidth / 1440) * PixPerInY)
End If

If AVISizeH > ((ScreenHeight / 1440) * PixPerInX) Then
AVISizeW = (((ScreenHeight / 1440) * PixPerInX) / AVISizeH) * AVISizeW
AVISizeH = ((ScreenHeight / 1440) * PixPerInX)
End If

ScreenTop = Int(((ScreenTop + (ScreenHeight / 2)) / 1440 * PixPerInY) - (AVISizeH / 2))
ScreenLeft = Int(((ScreenLeft + (ScreenWidth / 2)) / 1440 * PixPerInX) - (AVISizeW / 2))

Else 'Auto = False

'Non-proportionally resize .AVI to fit the display area
AVISizeW = Int((ScreenWidth / 1440) * PixPerInX)
AVISizeH = Int((ScreenHeight / 1440) * PixPerInY)
ScreenTop = Int((ScreenTop / 1440) * PixPerInY)
ScreenLeft = Int((ScreenLeft / 1440) * PixPerInX)

End If

'Put the AVI window on the display area
vid = AVIFunction(&quot;put TheVideo window at&quot; & &quot; &quot; & _
&quot; &quot; & ScreenLeft & &quot; &quot; & ScreenTop & _
&quot; &quot; & AVISizeW & &quot; &quot; & AVISizeH _
, 0&, 0, 0)


'Stop any playing .WAV
StopSound

'play the avi
vid = AVIFunction(&quot;play TheVideo&quot;, 0&, 0, 0)

TheEnd:
End Sub

Sub PauseAVI()

vid = AVIFunction(&quot;pause TheVideo&quot;, 0&, 0, 0)

End Sub

Sub ResumeAVI()

vid = AVIFunction(&quot;resume TheVideo&quot;, 0&, 0, 0)

End Sub

Sub StopAVI()

vid = AVIFunction(&quot;close TheVideo&quot;, 0&, 0, 0)

End Sub

Sub PlaySound(WAVFile As String)
Dim CmdStr As String

StopAVI 'Stop any playing AVI
StopSound 'Stop any playing .WAV

'Open the waveaudio device with WAVFile
CmdStr = (&quot;open &quot; & WAVFile & &quot; type waveaudio alias TheWAV&quot;)
vid = AVIFunction(CmdStr, 0&, 0, 0)
'Play WAVFile
vid = AVIFunction(&quot;play TheWAV&quot;, 0&, 0, 0)

End Sub

Sub StopSound()

'Stop any playing .WAV
vid = AVIFunction(&quot;close TheWAV&quot;, 0&, 0, 0)

End Sub
 

Public Declare Function PlaySound Lib &quot;winmm.dll&quot; Alias &quot;PlaySoundA&quot; (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Dim lngRC as Long

lngRC = PlaySound(&quot;c:\Program Files\Microsoft Office\Clipart\MMedia\Melorise.wav&quot;, 0&, 0&)


Tarek

The more I learn, the more I need to learn!
 
I haven't tested these controls yet, but try them to see if they work.
In the properties box set these commands to the values at right.

Multimedia control name : mmcEnv
Multimedia control DeviceType : WaveAudio
Multimedia control FileName : &quot;the name of the .wav file you want to load.&quot;

In code do this

Private Sub
mmcEnv.Command = &quot;Open&quot;
mmcEnv.Command = &quot;Play&quot;

End Sub
 
Just use the Playsound api that the guy above posted.
 
BrettyBaby

That's because you have to put the API in a module and then call it from your form...vb400's is the best way to do it. Regards,
Anth:cool:ny
----------------------------------------
&quot;You say [red]insanity[/red] like it's a BAD THING!&quot;
 
brettybaby-

Do like VB400 says. The PlaySound() api is an asynchronous call, which means that your program is able to respond to mouseclicks, etc, while the sound is playing.

Also do like WhiteTiger says, and put the &quot;public declare ...&quot; part in a .BAS module. You can then call it from anywhere in your code.

Chip H.
 
<RANT>
gnibbles, do you know how annoying that is?! Seagate, Micro$oft, CA you name them they're all doing it... I want a QUIET application utility.....
</RANT>

Sorry, just my 2p worth.....

Jim
 

You could add your own keys to:
HKEY_USERS\.DEFAULT\AppEvents\Schemes\Apps

It would then show up in the sound control appliet in the control panel. Your users could then assign, or not assign, a sound to the various events in your application.

Your application would of course have to read these registry locations at startup to see what the user has chosen, then play the correct sound at the correct time.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top