Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

New COM/ActiveX Control

QuickTime 7 for Windows includes a new QuickTime COM/ActiveX control. This new control is fully scriptable from Visual Basic, C#, JavaScript, C++, and other applications that can host COM objects.

This allows you to build stand-alone Windows applications that use QuickTime without needing to master QuickTime’s C/C++ API.

Important:  This new COM control is included in addition to the QuickTime ActiveX browser plug-in. They are not the same thing.

The new QuickTime COM control has an API that will be familiar to Visual Basic programmers and others used to working with COM objects. It is intended to make it easy to create stand-alone Windows applications that use QuickTime. The new COM control is not a browser plug-in, and will not run in a browser or other Web-based application.

For Web-based applications, use the QuickTime ActiveX browser plug-in; it is scriptable using JavaScript from most browsers using the same platform-independent API as the QuickTime browser plug-ins for Netscape and Safari. The QuickTime browser plug-in is the cross-platform solution for writing Web pages that interact with QuickTime.

Note: The API for controlling the QuickTime ActiveX browser plug-in using JavaScript can be found at: http://developer.apple.com/documentation/quicktime/Conceptual/QTScripting_JavaScript/index.html.

The remainder of this section is intended for programmers who want to provide high-level QuickTime movie playback and control, including some import, export, and editing capabilities, to Windows applications written in Visual Basic and other languages.

In this section:

Advantages For Developers
How It Works
Getting Started With QuickTime COM Control
Example Code To Create a Simple COM/ActiveX Control Application in Visual Basic 6


Advantages For Developers

If you are a Visual Basic programmer or enterprise software developer doing in-house development, the COM control implementation offers a number of important advantages:

For example, if your Windows server can run a Visual Basic, C#, or .js application that uses QuickTime, you have the possibility to create custom QuickTime content interactively, delivering that content over the Web. As long as your clients have QuickTime installed, your content will work with Windows and non-Windows clients, Internet Explorer and non-Internet Explorer browsers.

QuickTime Player itself uses the new QuickTime COM control for virtually all of its access to QuickTime.

Important:  The QuickTime 7 ActiveX browser plug-in is not scriptable via Visual Basic. It is scriptable, however, in JavaScript using the same syntax as the Netscape-style plug-in, and works the same on all browsers for Windows or Macintosh.

How It Works

The new COM control is comprised of two separate DLLs:

The COM library is a very thin layer that sits on top of the low level QuickTime APIs and provides a COM wrapper object for each logical QuickTime object. Each COM object exposes the properties, methods, and notifications of the QuickTime object it wraps.

The object hierarchy is illustrated in Figure 2-1.


Figure 2-1  The COM/ActiveX control object hierarchy

Figure 2-1 The COM/ActiveX control object hierarchy

Note that the QTMovieEqualizer object illustrated in Figure 2-1 should be QTFrequencyMeter.

If you are a Windows developer, you know that the Component Object Model (COM) specification defines how a host application accesses the component, how the component notifies the host application of events, standard data types for data exchange with the OS or other components. A COM control is a type of COM component that has a visual display of some kind, restricting its placement to visual containers such as a form or dialog box. COM controls typically manage their own window.

In the .NET environment, the new QuickTime COM control is accessed via the .NET Framework’s COM Interop layer. Primary Interop Assemblies (.NET wrappers for COM objects) will be provided with the QuickTime 7 SDK.

Note: The COM control does not provide a native managed code interface to QuickTime.

Visual Basic .NET and C#

The QuickTime COM control has a property page––that is, a dialog box that allows you to set some QuickTime control properties. You access the property page by clicking the Property Pages button in the toolbar on the Properties window.

To use the constants and enumerations associated with the QuickTime COM control, you must either explicitly precede them with the QTOControlLib namespace identifier, or else include an import for the QTOControlLib.

In Visual Basic, you do this with an Imports directive at the beginning of your module.

An example of using an explicit namespace identifier is, as follows:

AxQTControl1.Sizing = QTOControlLib.QTSizingModeEnum.qtControlFitsMovie
AxQTControl1.SetScale(2)
AxQTControl1.Sizing = QTOControlLib.QTSizingModeEnum.qtMovieFitsControl

The same example with imported namespace:

Imports QTOControlLib
AxQTControl1.Sizing = QTSizingModeEnum.qtControlFitsMovie
AxQTControl1.SetScale(2)
AxQTControl1.Sizing = QTSizingModeEnum.qtMovieFitsControl

In C#, the namespace can be imported with the using directive:

using QTOControlLib;

To use the constants and enumerations associated with the QT COM library, you must either explicitly precede them with the QTOLibrary namespace identifier, or else include an import (C#: using directive) for the QTOLibrary.

Important:  If you are working with QuickTime audio, when you open a movie using the COM/ActiveX control, you will get the pitch-preserving varispeed by default. This is not the case when you open a movie using legacy interfaces, nor when using NewMovieFromProperties without having set the kQTAudioPropertyID_RateChangesPreservePitch property to TRUE.

Getting Started With QuickTime COM Control

Once you instantiate the QuickTime COM control and load a movie into it, you can then get at the QTOLibrary object model via the control’s Movie property, which returns a QTMovie COM object.

To get started with the new COM control, in VB.NET or C#:

  1. Create a new Windows Application project.

  2. Right-click on the Windows Forms toolbox, choose Add/Remove Items... and select the COM Components tab.

  3. Scroll down until you find Apple QuickTime Control 2.0.

  4. Click this control and click OK to add the QuickTime control to your toolbox. You should now see a QuickTime icon.

  5. Place the control on Form1.

  6. Place two buttons on the form and code as follows:

 Private Sub Button1_Click(...) Handles Button1.Click
 
     AxQTControl1.URL = "d:\movies\sample.mov"  'Change to your own movie!
 
     End Sub
 
     Private Sub Button2_Click(...) Handles Button2.Click
 
         AxQTControl1.Movie.Play()
 
     End Sub

After you have completed these steps, you can:

  1. Build and run the application.

  2. Click Button1 to load a movie; then click Button2 to play the movie.

In Visual Basic 6, you need to follow these steps:

  1. Create a new Standard EXE project.

  2. Choose Project | Components and scroll down to the Apple QuickTime Control 2.0. Click this component and click OK to add to the Visual Basic 6 toolbox.

  3. Add the QuickTime control to Form1.

  4. Create two buttons and code as follows:

Private Sub Command1_Click()
          QTControl1.URL = "d:\movies\sample.mov" 'Change to your own movie!
 
      End Sub
 
      Private Sub Command2_Click()
 
          QTControl1.Movie.Play
 
      End Sub

Now you can run the application. Click Command1 to load the movie and Command2 to play the movie.

Once you have loaded a movie and have the QTMovie object from the control’s Movie property, you can proceed to delve down into the object model. For example:

 'Iterate movie tracks (VB6)
     Dim myMovie As QTMovie
     Dim t As String
 
     Set myMovie = QTControl1.Movie
 
     Dim trk As QTTrack
     Dim qtu As New QTUtils
     For Each trk In myMovie.Tracks
         t = t + "Track : " + CStr(i) + vbCrLf
         t = t + vbTab + "Type : " + qtu.FourCharCodeToString(trk.Type)
                                   + vbCrLf
         t = t + vbTab + "Format : " + trk.Format + vbCrLf
         t = t + vbTab + "Duration : " + CStr(trk.Duration) + vbCrLf
     Next trk
 
     txtResults = t$

In order to use the QuickTime COM object types in your Visual Basic 6 application you will need to add the QuickTime COM library to your project. Choose Project | References and add the Apple QuickTime Library 2.0.

Example Code To Create a Simple COM/ActiveX Control Application in Visual Basic 6

This section includes two code samples, one bare bones, letting you simply open and edit a QuickTime movie, and the other more fully featured. Using this example code you can create a simple COM/ActiveX control application in Visual Basic 6. The code is provided here with some comments and discussion.

Important:  A good learning tutorial on how to script the COM/ActiveX control is available at http://developer.apple.com/quicktime/activexcontrol.html and the sample code that lets you build a simple movie player application in Visual Basic 6 is available at http://developer.apple.com/samplecode/MoviePlayer/MoviePlayer.html. The sample demonstrates the following capabilities: movie playback with a movie controller, opening and closing movies, opening and closing movies from URLs, simple editing with cut, copy, and paste commands implemented; undo, export, export with a dialog, QuickTime event handling, Form resizing, error handling, fullscreen playback, as well as movie information display, such as duration, track types, track formats, and so on. If you are a Windows developer working with the new COM/ActiveX control, you are encouraged to explore both the tutorial and the sample code available, which extends the code examples #1 and #2 described in the next section, adding, in particular, export and QuickTime event notification functionality.

Code Example #1

The sample COM/ActiveX control application has a Form, with File and Edit menus. The File menu includes the following menu items:

The Edit menu includes these menu items:

If you want to edit any of these menus, you bring up the Form, go to Tools, then open the Menu Editor. The name of the menu determines the name of the handler that gets called.

In Example #1, Menu File_click is the handler that is called and passed the index. None of the menu items, as shown in Listing 2-1, are hooked up yet; when you click an item, it will exit the application.

If you look at the Form, you see there is an instance of the QuickTime Control. When you click an object in Visual Basic, it brings up the Property Inspector.

By default, when you create a new object, it takes the name of the class and appends a number to it. Unless you change it, it is called QTControl1. When it launches, there is an instance of this QTControl1 created.

Listing 2-1 shows you how to show an open a file and display a common dialog for the QuickTime control. The code in Listing 2-2 adds menu items to the File and Edit menu. The remaining code listings in Example #2 deal with sizing the movie, when you want to change the size of the movie to fit the size of the control, or display the movie at full screen. Example #2 also shows how to add an information window to the control, in addition to minimal error checking, and demonstrates how to respond to events.

Important:  Using Visual Basic, if you run a project, it may keep the control open, even when you quit the project. For any dll that QuickTime loads, Visual Basic keeps everything in your project loaded, so you can get into a state where you have to quit QuickTime and relaunch. After doing this, everything will work as expected.

Remember, you need to add the Apple QuickTime Control 2.0 and Microsoft Common Dialog Control 6.0 components to the project.

Listing 2-1  The GetFileName function to display a dialog for the QuickTime control

Function GetFileName()
 
    Form1.CommonDialog1.ShowOpen
    GetFileName = Form1.CommonDialog1.FileName
 
End Function

Listing 2-2  Adding menu items

Private Sub mnuEdit_Click(Index As Integer)
 
    Select Case Index
        Case 0  'Undo
        Case 2  'Cut
        Case 3  'Copy
        Case 4  'Paste
    End Select
 
End Sub
 
Private Sub mnuFile_Click(Index As Integer)
 
    Select Case Index
        Case 0  'Open
            QTControl1.URL = GetFileName()
        Case 1  'Close
        Case 3  'Full Screen
        Case 5  'Exit
            Unload Me
            End
    End Select
 
End Sub

Code Example #2

The following code (Example #2) provides a more fully featured QuickTime control. In this example, you add an information window, minimal error checking, and the capability of responding to events.

Follow these steps:

  1. Create a new VB6 Standard EXE project.

  2. Add the Apple QuickTime Control 2.0 and Microsoft Common Dialog Control 6.0 components to the project.

  3. Add the Apple QuickTime Library 2.0 reference to the project.

  4. Add two forms: Form1 and frmInfo.

  5. To Form1 add:

    1. File menu (mnuFile) with Open…, Open URL…, Close, Get Info, Full Screen and Exit menu items.

    2. Edit menu (mnuEdit) with Undo, Cut, Copy, Paste.

    3. A Common Dialog control (CommonDialog1).

    4. A QuickTime control (QTControl1).

  6. Set the menu items index values to match the corresponding index values in mnuFile_Click and mnuEdit_Click.

  7. To frmInfo add:

    1. 4 Label controls: lblName, lblInfo, lblCaptions and lblData with AutoSize = True

  8. Paste Listing 2-3 and Listing 2-4 into the code window of Form1 and Listing 2-5 into the code window of frmInfo.

Listing 2-3  The VB 6 code for the QuickTime control sample movie form

Object = "{7B92F833-027D-402B-BFF9-A67697366F4E}#1.0#0"; "QTOControl.dll"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form MovieForm
   Caption         =   "Movie"
   ClientHeight    =   4260
   ClientLeft      =   132
   ClientTop       =   816
   ClientWidth     =   4080
   LinkTopic       =   "MovieForm"
   ScaleHeight     =   4260
   ScaleWidth      =   4080
   StartUpPosition =   3  'Windows Default
   Begin MSComDlg.CommonDialog CommonDialog1
      Left            =   3240
      Top             =   600
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin QTOControlLibCtl.QTControl QTControl1
      Height          =   4332
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   4056
      _cx             =   7154
      _cy             =   7641
      BackColor       =   -2147483644
      BorderColor     =   0
      BorderStyle     =   0
      MovieControllerVisible=   -1  'True
      Sizing          =   0
      URL             =   ""
      BaseURL         =   ""
      AutoPlay        =   ""
   End
   Begin VB.Menu mnuBar
      Caption         =   "&File"
      Index           =   0
      Begin VB.Menu mnuFile
         Caption         =   "&Open..."
         Index           =   0
         Shortcut        =   ^O
      End
      Begin VB.Menu mnuFile
         Caption         =   "Open &URL..."
         Index           =   1
      End
      Begin VB.Menu mnuFile
         Caption         =   "&Close"
         Index           =   2
      End
      Begin VB.Menu mnuFile
         Caption         =   "-"
         Index           =   3
      End
      Begin VB.Menu mnuFile
         Caption         =   "&Full Screen"
         Index           =   4
      End
      Begin VB.Menu mnuFile
         Caption         =   "Get Info"
         Index           =   5
         Shortcut        =   ^I
      End
      Begin VB.Menu mnuFile
         Caption         =   "-"
         Index           =   6
      End
      Begin VB.Menu mnuFile
         Caption         =   "Exit"
         Index           =   7
      End
   End
   Begin VB.Menu mnuBar
      Caption         =   "Edit"
      Index           =   1
      Begin VB.Menu mnuEdit
         Caption         =   "Undo"
         Index           =   0
      End
      Begin VB.Menu mnuEdit
         Caption         =   "Cut"
         Index           =   2
      End
      Begin VB.Menu mnuEdit
         Caption         =   "Copy"
         Index           =   3
      End
      Begin VB.Menu mnuEdit
         Caption         =   "Paste"
         Index           =   4
      End
   End
End
Attribute VB_Name = "MovieForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim gManualFormResize As Boolean
 
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As  Long
Private Const SM_CYCAPTION = 4
Private Const SM_CYFRAME = 33
Private Const SM_CYMENU = 15
 
Function GetFileName()
    MovieForm.CommonDialog1.InitDir = "d:\QuickTime\Movies"
    MovieForm.CommonDialog1.ShowOpen
    GetFileName = MovieForm.CommonDialog1.FileName
End Function
 
Function GetFormBorderWidth()
    GetFormBorderWidth = GetSystemMetrics(SM_CYFRAME) * 2
End Function
 
Function GetFormBorderHeight()
    GetFormBorderHeight = GetSystemMetrics(SM_CYCAPTION) +  GetSystemMetrics(SM_CYMENU) + (GetSystemMetrics(SM_CYFRAME) * 2)
End Function
 
Private Sub Form_Load()
    QTControl1.ErrorHandling = qtErrorHandlingRaiseException
    QTControl1.Sizing = qtControlFitsMovie
    Load MovieInfo
End Sub
 
Private Sub Form_Resize()
    Dim oldSizingMode As QTSizingModeEnum
 
    gManualFormResize = True  ' global flag so _SizeChanged won't respond
 
    ' change sizing mode so the movie tracks the control's size
    oldSizingMode = QTControl1.Sizing
    QTControl1.Sizing = qtMovieFitsControl
    QTControl1.Move 0, 0, Me.Width - (GetFormBorderWidth() *  Screen.TwipsPerPixelX), Me.Height - (GetFormBorderHeight() *  Screen.TwipsPerPixelY)
    QTControl1.Sizing = oldSizingMode
 
    gManualFormResize = False
End Sub
 
Private Sub Form_Unload(Cancel As Integer)
    MovieInfo.SetInfoMovie Nothing
    QTControl1.URL = ""
    DoEvents
    End
End Sub
 
Private Sub mnuEdit_Click(Index As Integer)
    If QTControl1.Movie Is Nothing Then Exit Sub
    Select Case Index
        Case 0 ' Undo
            QTControl1.Movie.Undo
        Case 2 ' Cut
            QTControl1.Movie.Cut
        Case 3 ' Copy
            QTControl1.Movie.Copy
        Case 4 ' Paste
            QTControl1.Movie.Paste
    End Select
End Sub
 
Private Sub mnuFile_Click(Index As Integer)
    On Error GoTo ErrorHandler
    Dim filePath
    Select Case Index
        Case 0  ' Open
            filePath = GetFileName()
            If filePath <> "" Then
                QTControl1.URL = filePath
                MovieInfo.SetInfoMovie QTControl1.Movie
            End If
        Case 1  ' Open URL
            Dim movieURL As String
            movieURL = InputBox("Enter a URL:", "URL", "http://www.server.com/ movies/sample.mov")
            If movieURL <> "" Then
                QTControl1.URL = movieURL
                MovieInfo.SetInfoMovie QTControl1.Movie
            End If
        Case 2  ' Close
            QTControl1.URL = ""
            MovieInfo.SetInfoMovie Nothing
        Case 4  'Full Screen
            If QTControl1.URL <> "" Then QTControl1.FullScreen = True
        Case 5  ' Get Info
            MovieInfo.SetInfoMovie QTControl1.Movie
            MovieInfo.Move Me.Left + Me.Width + 200, Me.Top
            MovieInfo.Show
        Case 7  ' Exit
            Unload Me
            End
    End Select
 
    Exit Sub
 
ErrorHandler:
    Beep
    Dim errStr As String
    errStr = "Failed with error #" & Hex(Err.Number) & ", " & Err.Description
    MsgBox errStr, vbCritical
End Sub
 
Private Sub QTControl1_SizeChanged(ByVal Width As Long, ByVal Height As Long)
    ' ignore event if control was resized as a result of form being resized.
    If gManualFormResize Then Exit Sub
 
   ' resize window to accomodate control
    Me.Move Me.Left, Me.Top, (Width + GetFormBorderWidth()) *  Screen.TwipsPerPixelX, (Height + GetFormBorderHeight()) * Screen.TwipsPerPixelY
End Sub
 
Private Sub QTControl1_StatusUpdate(ByVal statusCodeType As Long, ByVal statusCode  As Long, ByVal statusMessage As String)
     Select Case statusCodeType
        Case qtStatusCodeTypeControl
            Select Case statusCode
                Case qtStatusFullScreenBegin
                    Me.Hide  ' hide movie window
 
                Case qtStatusFullScreenEnd
                    QTControl1.SetScale 1  ' set back to a reasonable size
                    Me.Show
        End Select
    End Select
End Sub
 

Listing 2-4  The VB 6 code for the movie information form

Begin VB.Form MovieInfo
   BorderStyle     =   4  'Fixed ToolWindow
   Caption         =   "Movie Info"
   ClientHeight    =   5148
   ClientLeft      =   48
   ClientTop       =   288
   ClientWidth     =   5880
   LinkTopic       =   "Form2"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5148
   ScaleWidth      =   5880
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame1
      Height          =   3495
      Left            =   120
      TabIndex        =   2
      Top             =   1560
      Width           =   5655
      Begin VB.Label lblData
         Height          =   3135
         Left            =   1560
         TabIndex        =   4
         Top             =   240
         Width           =   3975
      End
      Begin VB.Label lblCaptions
         Alignment       =   1  'Right Justify
         BeginProperty Font
            Name            =   "MS Sans Serif"
            Size            =   7.8
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   3135
         Left            =   120
         TabIndex        =   3
         Top             =   240
         Width           =   1335
      End
   End
   Begin VB.Label lblInfo
      Alignment       =   2  'Center
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   7.8
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   975
      Left            =   120
      TabIndex        =   1
      Top             =   480
      Width           =   5535
   End
   Begin VB.Label lblName
      Alignment       =   2  'Center
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   9.6
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5535
   End
End
Attribute VB_Name = "MovieInfo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
 
Dim gMovie As QTMovie
 
Private Sub Form_Load()
    DisplayMovieData
End Sub
 
Sub SetInfoMovie(myMovie As QTMovie)
    Set gMovie = myMovie
    DisplayMovieData
End Sub
 
Function MovieAnnotation(annoID As Long, mov As QTMovie) As String
    ' Annotation returns an error if asked for an annotation that
    '  does not exist (so you can tell the difference between an
    '  annotation that is missing and one that is set to an empty
    '  string), so we need to be prepared for an exception
    On Error Resume Next
    Dim anno As String
 
    anno$ = ""   ' value will remain if getting value throws exception
    If Not (mov Is Nothing) Then anno$ = mov.Annotation(annoID)
    MovieAnnotation = anno
End Function
 
Sub DisplayMovieData()
    Dim dataStr As String
    Dim captionsStr As String
    Dim annoStr As String
 
    Dim track As QTTrack
 
    lblName = ""
    lblInfo = ""
    lblCaptions = ""
    lblData = ""
 
    If gMovie Is Nothing Then Exit Sub
 
    On Error GoTo ErrorHandler
    lblName = MovieAnnotation(qtAnnotationFullName, gMovie)
 
    ' get some annotations
    lblInfo = ""
    annoStr = MovieAnnotation(qtAnnotationCopyright, gMovie)
    If Trim(annoStr) <> "" Then lblInfo = lblInfo & annoStr & vbCrLf
    annoStr = MovieAnnotation(qtAnnotationAuthor, gMovie)
    If Trim(annoStr) <> "" Then lblInfo = lblInfo & annoStr & vbCrLf
    annoStr = MovieAnnotation(qtAnnotationComments, gMovie)
    If Trim(annoStr) <> "" Then lblInfo = lblInfo & annoStr & vbCrLf
    annoStr = MovieAnnotation(qtAnnotationDescription, gMovie)
    If Trim(annoStr) <> "" Then lblInfo = lblInfo & annoStr & vbCrLf
 
    captionsStr = "Source:" & vbCrLf & vbCrLf
    dataStr = Trim(gMovie.URL) & vbCrLf & vbCrLf
 
    captionsStr = captionsStr & "Size:" & vbCrLf & vbCrLf
    dataStr = dataStr & gMovie.Width & " x " & gMovie.Height & vbCrLf & vbCrLf
 
    captionsStr = captionsStr & "Duration:" & vbCrLf & vbCrLf
    dataStr = dataStr & gMovie.Duration & vbCrLf & vbCrLf
 
    For Each track In gMovie.Tracks
        captionsStr = captionsStr & track.DisplayName & ":" & vbCrLf
        dataStr = dataStr & track.Format
        If track.Height > 0 Then
            dataStr = dataStr & ", " & track.Width & " x " & track.Height & vbCrLf
        End If
    Next track
 
    lblCaptions = captionsStr
    lblData = dataStr
    Exit Sub
 
ErrorHandler:
    dataStr = dataStr & "Error #" & Hex(Err.Number) & ", " & Err.Description &  vbCrLf
    Resume Next
End Sub

Listing 2-5  Code for handling the sizing of the QuickTime movie

Option Explicit
Dim bFormResized As Boolean
 
Private Sub Form_Load()
 
    QTControl1.ErrorHandling = qtErrorHandlingRaiseException
    QTControl1.sizing = qtControlFitsMovie
    Load frmInfo
 
End Sub
 
Private Sub Form_Resize()
    Dim sizingMode As QTSizingModeEnum
    Dim resetSizing As Boolean
 
    bFormResized = True
 
    ' set the sizing mode to "movie fits control" so the movie will adjust
    '  itself as to the new control size
    sizingMode = QTControl1.sizing
    If sizingMode = qtControlFitsMovie Then
        QTControl1.sizing = qtMovieFitsControl
        resetSizing = True
    Else
        resetSizing = False
    End If
 
    QTControl1.Move 0, 0, Me.Width - (GetFormBorderWidth() *  Screen.TwipsPerPixelX), Me.Height - (GetFormBorderHeight() *  Screen.TwipsPerPixelY)
 
    If resetSizing Then QTControl1.sizing = sizingMode
 
    bFormResized = False
End Sub
 
 
Private Sub Form_Unload(Cancel As Integer)
 
    frmInfo.SetInfoMovie Nothing
    QTControl1.URL = ""
    DoEvents
    End
 
End Sub
 
Private Sub mnuEdit_Click(Index As Integer)
 
    Select Case Index
        Case 0  'Undo
            QTControl1.Movie.Undo
        Case 2  'Cut
            QTControl1.Movie.Cut
        Case 3  'Copy
            QTControl1.Movie.Copy
        Case 4  'Paste
            QTControl1.Movie.Paste
    End Select
 
End Sub
 
Private Sub mnuFile_Click(Index As Integer)
 
    Dim FileName
 
    Select Case Index
 
        Case 0  'Open
            ' make the control automatically resize itself whenever the movie
            ' size changes
            QTControl1.sizing = qtControlFitsMovie
 
            FileName = GetFileName()
            If FileName <> "" Then
 
                QTControl1.URL = FileName
 
                If frmInfo.Visible Then
                    frmInfo.SetInfoMovie QTControl1.Movie
                End If
 
            End If
 
 
        Case 1  'Open URL
            QTControl1.sizing = qtControlFitsMovie
 
            Dim URL$
 
            URL$ = InputBox("Enter a URL:", "URL", "http://www.server.com/movies/ sample.mov")
 
            If URL$ <> "" Then
 
                QTControl1.URL = URL$
 
                If frmInfo.Visible Then
                    frmInfo.SetInfoMovie QTControl1.Movie
                End If
 
            End If
 
        Case 2  'Close
            frmInfo.SetInfoMovie Nothing
            QTControl1.URL = ""
            frmInfo.Hide
        Case 4  'Full Screen
            If QTControl1.URL <> "" Then QTControl1.FullScreen = True
        Case 5  'Get Info
            If QTControl1.URL <> "" Then
                frmInfo.SetInfoMovie QTControl1.Movie
                frmInfo.Move Me.Left + Me.Width + 200, Me.Top
                frmInfo.Show
            End If
        Case 7  'Exit
            Unload Me
            End
 
    End Select
 
End Sub
 
Private Sub QTControl1_SizeChanged(ByVal Width As Long, ByVal Height As Long)
 
    ' Ignore event if control was resized as a result of form being resized.
    '  avoids race condition
    If bFormResized Then Exit Sub
 
    'Resize window to accomodate control
    Me.Move Me.Left, Me.Top, (Width + GetFormBorderWidth()) *  Screen.TwipsPerPixelX, (Height + GetFormBorderHeight()) * Screen.TwipsPerPixelY
 
End Sub


< Previous PageNext Page > Hide TOC


Last updated: 2005-11-09




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice