Microsoft KB Archive/131819

= How to Display Text on a Playing .AVI File =

Article ID: 131819

Article Last Modified on 10/30/2003

-

APPLIES TO


 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q131819



SUMMARY
This article shows by example how to display text on top of an .AVI file playing in a picture box by using the Print method for a picture box control and the TextOut API for other controls on a form. To apply the information in this article, you must have Video for Windows drivers correctly installed and a valid .AVI file available.



MORE INFORMATION
The MCI control refreshes the picture box control when each frame is displayed. This causes the picture box control to be repainted, wiping out any text printed there. The following sample code demonstrates a technique using a timer to repaint the text as often as possible. This ensures that the text only blinks when the MCI control refreshes the picture control.

Step-by-Step Example with Picture Box and Print Method
 Open the project VB\Samples\MCI\Mcitest.mak. Make the changes described in the following article in the Microsoft Knowledge Base:

98769 Playing an .AVI File with the MCITEST Example

 Select the Animate.frm form, and add a timer control.  Add the following code to the Timer1_Timer event procedure: Sub Timer1_Timer Dim MyStr As String MyStr = "Testing Testing" ''String you want to display picture1.CurrentX = 10 picture1.CurrentY = 10 picture1.Print MyStr$ End Sub   Modify the code in the AI_OPEN Click event procedure:

Original code: ' Play the movie into the picture control. On Error GoTo MCI_ERROR mmcontrol1.Command = "Play" Change to: ' Play the movie into the picture control. On Error GoTo MCI_ERROR Timer1.Interval = 50 ''This number is the refresh rate mmcontrol1.Command = "Play"  Save the work, and run the application.</ol>

Step-by-Step Example with Picture Box and TextOut API Call
The TextOut API provides a method for printing text on objects which have hDCs but no Print methods.

<ol> Open the project VB\Samples\MCI\Mcitest.mak.</li> Make the changes described in the following article in the Microsoft Knowledge Base:

98769 Playing an .AVI File with the MCITEST Example

</li> Select the Animate.frm form, and add a timer control.</li>  Add the following code to the Timer1_Timer event procedure: Sub Timer1_Timer Dim RetVal As Integer ''The return value of TextOut - Ignored. Dim xPos As Integer, yPos As Integer Dim MyStr As String, MyLen As Integer

xPos = 10 ''x coordinate where you want the text to display yPos = 10 ''y coordinate where you want the text to display MyStr = "Testing Testing" ''String you want to display MyLen = Len(MyStr) ''Length of string

'Display the text on top of picture1 (location where AVI is playing) RetVal= TextOut(Picture1.hDC, xPos, yPos, MyStr, MyLen) End Sub </li>  Modify the code in the AI_OPEN Click event procedure:

Original code: ' Play the movie into the picture control. On Error GoTo MCI_ERROR mmcontrol1.Command = "Play" Change to: ' Play the movie into the picture control. On Error GoTo MCI_ERROR Timer1.Interval = 50 ''This number is the refresh rate mmcontrol1.Command = "Play" </li>  Add the following line of code to the (general) (declarations) section of Global.bas: ' Enter the following Declare statement as one, single line: Declare Function TextOut Lib "GDI" (ByVal hDC As Integer, ByVal X As     Integer, ByVal Y As Integer, ByVal lpString As String, ByVal nCount      As Integer) As Integer </li> Save the work, and run the application.</li></ol>

Additional query words: 3.00 multimedia multi-media

Keywords: KB131819

-

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

© Microsoft Corporation. All rights reserved.