Solved

Add In

Posted on 1998-07-15
3
317 Views
Last Modified: 2008-02-01
I would like to be able to enable and disable commandbar controls based on which window in the VB IDE is active (i.e. the codepane window) but I don't know of any objects which 'listen' for these events.
0
Comment
Question by:markmcc
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
tomook earned 100 total points
ID: 1465811
VB5 Add-Ins can do what you want. I assume you can create an Add-In from the New Project menu. Assuming you use the default template, go to the class "Connection" and put these two lines in the Declarations section:

Public WithEvents mVBComponentEvents As VBComponentsEvents
Public WithEvents mVBProjEvents As VBProjectsEvents

Near the top of IDTExtensibility_OnConnection, after the line
    Set VBInstance = VBInst
add:
    Set mVBProjEvents = VBInstance.Events.VBProjectsEvents
    If Not (VBInstance.ActiveVBProject Is Nothing) Then
        Set mVBComponentEvents = VBInstance.Events.VBComponentsEvents(VBInstance.ActiveVBProject)
    End If

Then add the following event handlers:
Private Sub mVBComponentEvents_ItemActivated(ByVal VBComponent As VBIDE.VBComponent)
    ' This is probably where you want to do your command bar manipulations.
    ' Check out the CommandBars property of the variable VBInstance.
    MsgBox "Activated component " & VBComponent.Name
End Sub

Private Sub mVBComponentEvents_ItemAdded(ByVal VBComponent As VBIDE.VBComponent)
    MsgBox "Added component " & VBComponent.Name
End Sub

Private Sub mVBComponentEvents_ItemReloaded(ByVal VBComponent As VBIDE.VBComponent)
    MsgBox "Reloaded component " & VBComponent.Name
End Sub

Private Sub mVBComponentEvents_ItemRemoved(ByVal VBComponent As VBIDE.VBComponent)
    MsgBox "Removed component " & VBComponent.Name
End Sub

Private Sub mVBComponentEvents_ItemRenamed(ByVal VBComponent As VBIDE.VBComponent, ByVal OldName As String)
    MsgBox "Renamed component " & OldName & " to " & VBComponent.Name
End Sub

Private Sub mVBComponentEvents_ItemSelected(ByVal VBComponent As VBIDE.VBComponent)
    MsgBox "Selected component " & VBComponent.Name
End Sub

Private Sub mVBProjEvents_ItemActivated(ByVal VBProject As VBIDE.VBProject)
    Set mVBComponentEvents = VBInstance.Events.VBComponentsEvents(VBProject)
End Sub

Private Sub mVBProjEvents_ItemAdded(ByVal VBProject As VBIDE.VBProject)
    Set mVBComponentEvents = VBInstance.Events.VBComponentsEvents(VBProject)
End Sub

Private Sub mVBProjEvents_ItemRemoved(ByVal VBProject As VBIDE.VBProject)
    Set mVBComponentEvents = VBInstance.Events.VBComponentsEvents(VBProject)
End Sub

Private Sub mVBProjEvents_ItemRenamed(ByVal VBProject As VBIDE.VBProject, ByVal OldName As String)
    Set mVBComponentEvents = VBInstance.Events.VBComponentsEvents(VBProject)
End Sub

The code here just pops up message boxes, but you can just as well manipulate command bars.
0
 

Author Comment

by:markmcc
ID: 1465812
I wanted to know which windows (codepane, property, toolbar, immediate, etc.) in the VB IDE was active not the components (forms, modules, classes etc).  I've found out that VB doesn't provide hooks in these events.  One way to do this, however, is to place a timer control on a form and use the ActiveWindow property of the VBE object.
0
 
LVL 4

Expert Comment

by:tomook
ID: 1465813
It looks like the VB team did not think anyone would want to know that. Good luck. Do you mind my asking what this is for?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now