Microsoft KB Archive/96090

= How to Use Windows 3.1 APIs to Play Videos in Visual Basic =

Article ID: 96090

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition

-



This article was previously published under Q96090



SUMMARY
You can play video .AVI files in Visual Basic by using Windows version 3.1 APIs.

NOTE: You must have the video for Windows driver installed on your system. Choose the Drivers icon from Control Panel to see what driver(s) you have installed. The driver you need is [MCI] Microsoft Video for Windows.



MORE INFORMATION
Use the following procedure to position and size the window where you want to play the .AVI file and to play the .AVI file:

 Run Visual Basic, or if Visual Basic is already running, choose New Project from the File menu (ALT, F, N). Form1 is created by default. Add a command button control (Command1) to Form1.  Add the following code to the Command1_Click event of Form1: Sub Command1_Click Dim CmdStr As String Dim ret As Long Dim ErrorStr As String

ErrorStr = Space(255) '*** This will open the AVIVideo and create a child window on the '*** form where the video will display. Animation is the device_id. '*** Replace c:\rbtndog.avi with the AVI you want to play. You must '*** put use the full path, for example, c:\tmp\avi\avifiletoplay.avi CmdStr =(&quot;open c:\tmp\rbtndog.avi type AVIVideo alias Animation parent &quot;          + LTrim$(Str$(form1.hWnd)) + &quot; style &quot; + LTrim$(Str$(WS_CHILD))) ret = mciSendString(CmdStr, 0&, 0, 0) If ret > 0 Then ret = mciGetErrorString(ret, ErrorStr, 255) MsgBox ErrorStr End If  '*** Put the window at location 10 10 relative to the parent window '*** with a size of 200 200 ret = mciSendString(&quot;put Animation window at 10 10 200 200&quot;, 0&, 0, 0) If ret > 0 Then ret = mciGetErrorString(ret, ErrorStr, 255) MsgBox ErrorStr End If

'*** The wait tells the MCI command to complete before returning '*** control to the application. ret = mciSendString(&quot;play Animation wait&quot;, 0&, 0, 0) If ret > 0 Then ret = mciGetErrorString(ret, ErrorStr, 255) MsgBox ErrorStr End If

'*** Close windows so they don't crash when you exit the application. ret = mciSendString(&quot;close Animation&quot;, 0&, 0, 0) If ret > 0 Then ret = mciGetErrorString(ret, ErrorStr, 255) MsgBox ErrorStr End If

End Sub   Choose New Module from the File menu (ALT, F, M). MODULE1.BAS is created by default. Add the following code to Module1. Enter the entire Declare on a single line: Global Const WS_CHILD = &H40000000 Declare Function mciSendString Lib &quot;mmsystem&quot; (ByVal lpstrCommand$,     ByVal lpstrReturnStr As Any, ByVal wReturnLen%, ByVal hCallBack%) As Long Declare Function mciGetErrorString Lib &quot;mmsystem&quot; (ByVal dwError&,     ByVal lpstrReturnStr As Any, ByVal wReturnLen%) As Long  From the Run menu, choose Start (ALT, R, S) or press the F5 key to run the program.

For more information on the sndSendString function and command strings, see pages 3-26 and 7-23 to 7-93 in the &quot;MultiMedia Programmer's Reference.&quot;

Additional query words: 2.00 3.00

Keywords: kbcode KB96090

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.