Results 1 to 3 of 3

Thread: With Events

  1. #1

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    63
    Does anyone have a sample project for an ActiveX EXE that has custom events. In another project I need to create an instance of the ActiveX EXE and act upon the ActiveX object's events. Never done this before.

  2. #2
    Guest

    Please explain

    Ok so that was an aussie joke.....

    Perhaps detail what you are trying to do, not quite sure were you are going with "Events" and ActiveX

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Here's an example ActiveX EXE I wrote which can be added to an application to allow multiple instances of the app that get started to pass their command line to the original instance before closing, sort of like WinAmps "Enqueue" functionality:

    In an ActiveX EXE Project named "AppExtender":

    Add 2 Class Modules and a Standard Module, call the Class Modules; "CommandLine" and "Connector":

    In the "CommandLine" Class Module:
    Code:
    'In a Class Module Called:  CommandLine
    'Set Instancing to 2 - PublicNotCreatable
    '
    Public Event Change()
    Private sString As String
    
    Public Property Get szString() As String
        'Return the Value of the szString Property
        szString = sString
    End Property
    
    Public Property Let szString(ByVal vNewValue As String)
        'Set the Value of the szString Property and Trigger
        'the Change Event
        sString = vNewValue
        RaiseEvent Change
    End Property
    In the "Connector" Class Module:
    Code:
    'In a Class Module Called:  Connector
    'Instancing:                5 - MultiUse
    '
    Private Sub Class_Initialize()
        'If the Global CommandLine Object isn't Initialized, then Initialize it
        If oCommandLine Is Nothing Then
            Set oCommandLine = New CommandLine
        End If
        'Increment the number of Connections to this Object
        lConnected = lConnected + 1
    End Sub
    
    Private Sub Class_Terminate()
        'Decrement the Number of Connections to this Object
        lConnected = lConnected - 1
        'If the No. of Connections is Zero, Destroy the Global
        'Command Line Object, Releasing the ActiveX EXE
        If lConnected = 0 Then Set oCommandLine = Nothing
    End Sub
    
    Public Property Get CommandLine() As CommandLine
        'Return a Reference to the Global CommandLine Object
        Set CommandLine = oCommandLine
    End Property
    In the Standard Module:
    Code:
    'In a Class Module Called:  Connector
    'Instancing:                5 - MultiUse
    '
    Private Sub Class_Initialize()
        'If the Global CommandLine Object isn't Initialized, then Initialize it
        If oCommandLine Is Nothing Then
            Set oCommandLine = New CommandLine
        End If
        'Increment the number of Connections to this Object
        lConnected = lConnected + 1
    End Sub
    
    Private Sub Class_Terminate()
        'Decrement the Number of Connections to this Object
        lConnected = lConnected - 1
        'If the No. of Connections is Zero, Destroy the Global
        'Command Line Object, Releasing the ActiveX EXE
        If lConnected = 0 Then Set oCommandLine = Nothing
    End Sub
    
    Public Property Get CommandLine() As CommandLine
        'Return a Reference to the Global CommandLine Object
        Set CommandLine = oCommandLine
    End Property
    Compile the ActiveX EXE then add a reference to it in a new Standard Project:

    Add a Module and Set the StartupObject to "SubMain()"
    Add a Textbox to the Form:

    In the Form:
    Code:
    'Create a Private Instance of the CommandLine Object with
    'the Change Event, which will Trigger Each Time the szString
    'Property of the CommandLine Object is Changed, in any App.
    Private WithEvents oCommandLine As AppExtender.CommandLine
    
    Private Sub Form_Load()
        'Get the CommandLine Object from the Public Connector
        Set oCommandLine = oConnector.CommandLine
    End Sub
    
    Private Sub oCommandLine_Change()
        'Triggered when the value of szString changes
        Text1 = oCommandLine.szString
    End Sub
    In the Module:
    Code:
    'Create a Private Instance of the CommandLine Object
    'So that we can still change the Commandline if
    'we have to unload this Instance..
    Private oCommandLine As AppExtender.CommandLine
    'Create a Public Connector Object, used to get a
    'Reference to the Globally Shared CommandLine Object..
    Public oConnector As New AppExtender.Connector
    
    Sub Main()
        'Get the CommandLine Object..
        Set oCommandLine = oConnector.CommandLine
        'If this is the 1st Instance, show the Form
        If Not App.PrevInstance Then Form1.Show
        'Set the CommandLine Object's szString Property to
        'this instances CommandLine, Triggering the Change
        'Event of the CommandLine Object in the Other Instance.
        oCommandLine.szString = Command
    End Sub
    Compile the Project EXE then drag and drop a file onto the EXE, the first time you do it, it'll load the Form and display the Path and filename of the file you dropped in the Textbox, now leave it open and drag another file onto the EXE, this time it'll just update the original forms textbox to show the new Path anf filename.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width