How to Display Text on a Playing .AVI File

Last reviewed: August 14, 1995
Article ID: Q131819
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

  1. Open the project VB\Samples\MCI\Mcitest.mak.

  2. 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
    
    

  3. Select the Animate.frm form, and add a timer control.

  4. 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
    
    

  5. 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"
    

  6. 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.

  1. Open the project VB\Samples\MCI\Mcitest.mak.

  2. 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
    
    

  3. Select the Animate.frm form, and add a timer control.

  4. 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
    
    

  5. 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"
    

  6. 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
    
    

  7. Save the work, and run the application.


Additional reference words: 3.00 multimedia multi-media
KBCategory: kbprg kbmm kbcode
KBSubCategory: PrgCtrlsCus


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 14, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.