http://www.vb-helper.com/HowTo/newctl3.zip

	Purpose
Load an ActiveX control at run time

	Method
Use the Controls collection's Add method.

First load the SayHello project and select the File menu's Make SayHello.ocx
command to build the control. Then load the test program and run it.


Robert Heinig (rheinig-beikuk@gmx.net) found a problem trying to load an Acrobat Reader ActiveX control. Here's the code he used:

	Option Explicit

	' For this sample to work, do one of the following:
	' a) Comment out the pdf.LoadFile call
	' - or -
	' b) include the "Acrobat Control for ActiveX"
	'    in your toolbox (comes with the Acrobat Reader),
	'    And turn the Project Option "remove unused ActiveX..." off.
	' Plus, You need any Acrobat 4.0x reader installed.

	' My guess is the cause is the difference between
	' the names "PdfLib.Pdf" (Typelib name, Class name)
	' and "Pdf.PdfCtrl.1" (the ProgID), VB just doesn't
	' call QueryInterface correctly unless it already
	' knows about the ProgID/Class name correlation!

	' There's probably a workaround, but I can only think
	' of a vtable hack right now - a bit over the top for this.

	Dim pdf As Control
	' Same behaviour if declared as PdfLib.Pdf, Control or Object.

	Private Sub Command1_Click()
	    Dim v As Variant, sFile As String

	    Set pdf = Controls.Add("Pdf.PdfCtrl.1", "pdf")
	    pdf.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
	    Command1.Visible = False
	    pdf.Visible = True
    
	    For Each v In Array("Readme", "Liesmich", "Leame", "Lisezmoi")
	        sFile = "C:\Progra~1\Adobe\Acroba~1.0\Reader\" & v & ".pdf"
	        If Len(Dir$(sFile)) > 0 Then
	            pdf.LoadFile sFile
	            Exit For
	        End If
	    Next
	End Sub

	Private Sub Form_Resize()
	    On Error Resume Next
	    pdf.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
	End Sub


	Disclaimer
This example program is provided "as is" with no warranty of any kind. It is
intended for demonstration purposes only. In particular, it does no error
handling. You can use the example in any form, but please mention
www.vb-helper.com.
