Hooking the VTABLE of an Event Interface ?
Hi all,
Is it possible to hook the VTable of an Event Interface such as the ICommandBarButtonEvents of the Microsoft Office Object Library ? ICommandBarButtonEvents Interface GUID ="{55F88890-7708-ACEB-C000-006008961DA5}"
I can successfully hook the Properties and Methods but not the Click event
Thank you
Re: Hooking the VTABLE of an Event Interface ?
Bump
Any thoughts anyone ?
Re: Hooking the VTABLE of an Event Interface ?
Re: Hooking the VTABLE of an Event Interface ?
I've never done it from VB6, but it's possible, at least in some form.
My wife is a professor, and she uses this little program called PhraseExpress that somehow latches itself onto Word. When she's reviewing student papers, she has "codes" that she can type in, like "arpq". When she types in these codes, Word (via PhraseExpress) will automatically do various tasks, like possibly make a side-bar comment that's an entire paragraph. I've never used it, but apparently it can do many things from just typing in these codes that you create.
However, the more I think about it, it's probably an add-in into Word, which probably does give you some access to events within Word (such as document_changed). I try to stay away from the VBA and various add-ins as much as I can, but I'm sure there are ways to do it.
To actually contemplate doing it from VB6 though would be a bit strange. This would be a bit like a keyboard sniffer, which is rather discouraged.
Elroy
Regards,
Re: Hooking the VTABLE of an Event Interface ?
What do you mean (more detail or even project)? Of course you can hook an interface method if you have the such variable.
Re: Hooking the VTABLE of an Event Interface ?
@Trick, I think he's wanting to hook events in MS-Word and see them in VB6, sort of like "WithEvents" for a word document. The methods are trivially "hooked" by just using automation.
Re: Hooking the VTABLE of an Event Interface ?
Quote:
Originally Posted by Elroy
I think he's wanting to hook events in MS-Word and see them in VB6, sort of like "WithEvents" for a word document. The methods are trivially "hooked" by just using automation.
Hmm, if so, RAFAAJ2000, no need to hook. Just use standard strategy.
Here is an example:
Code:
Option Explicit
Private WithEvents oButton As CommandBarButton
Private oWord As Word.Application
Private Sub cmdCreate_Click()
Dim PanelName As String
Dim oDoc As Word.Document
Dim oBars As CommandBars
Dim oBar As CommandBar
Set oWord = New Word.Application
With oWord
.Visible = True
.Activate
.WindowState = wdWindowStateMaximize
Set oDoc = .Documents.Add(, , , True)
End With
Set oDoc = oWord.Documents(1)
Set oBars = oDoc.CommandBars
PanelName = "My Bar"
Set oBar = oBars.Add(Name:=PanelName, Position:=msoBarTop, _
MenuBar:=False, Temporary:=True)
oBar.Enabled = True
oBar.Visible = True
Set oButton = oBar.Controls.Add(Type:=msoControlButton)
End Sub
Private Sub cmdClose_Click()
oWord.Documents.Close False
oWord.Quit
Set oWord = Nothing
End Sub
Private Sub oButton_Click(ByVal Ctrl As CommandBarButton, CancelDefault As Boolean)
MsgBox "Event: CommandBar Button Clicked."
End Sub
Add references to:
1. Microsoft Office xx Object Library
2. Microsoft Word xx Object Library
and 2 buttons on VB Form cmdCreate and cmdClose. Run, press cmdCreate, switch to Word, press button on new bar, so, you'll get event in your app.
Best regards,
Alex.
Re: Hooking the VTABLE of an Event Interface ?
Thanks for answering but hooking the CommandBarButton Click event in the way that Elroy and Dragokas kindly suggested only works with versions of Office prior to Office 2007 .. With the advent of the Ribbon in Office 2007 and later, that approach does'nt work anymore
Still hoping to find an API based (low level) solution.
Regards