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, "AVI Error"
GoTo TheEnd
End If
'Determine the .AVI Height and Width
vid = AVIFunction("status TheVideo window handle", 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
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
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 : "the name of the .wav file you want to load."
In code do this
Private Sub
mmcEnv.Command = "Open"
mmcEnv.Command = "Play"
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,
Anthny
----------------------------------------
"You say [red]insanity[/red] like it's a BAD THING!"
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 "public declare ..." part in a .BAS module. You can then call it from anywhere in your code.
<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>
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.