The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for
Windows, version 3.0
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:
ARTICLE-ID:Q98769
TITLE :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.
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.
- Open the project VB\Samples\MCI\Mcitest.mak.
- Make the changes described in the following article in the Microsoft
Knowledge Base:
ARTICLE-ID:Q98769
TITLE :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 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
- 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"
- 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
- Save the work, and run the application.
|