Creating a Context Menu Handler
Let’s put all of this into
action and actually implement a context menu handler for the
.rad file. We’ll add a context menu item
that displays the noise an animal makes in a message box. The menu
item itself will be displayed in the format
(Animal
Name)
Noise . Animal
Name will be determined from the
.rad file in question. Let’s begin.
Type Library
The first step to creating the
.rad file context menu handler is to compile the
type library containing the interface definitions and constants that
will be needed from VB. Constants and UDTs will also be put into the
type library with their associated interfaces. But only the groups of
constants that are needed will be put in the library. For instance,
we need the menu constants MF_BYPOSITION,
MF_STRING, and MF_SEPARATOR.
Therefore, the library will contain all of the MF_
constants. We don’t need any of the menu
state constants (MFS_ ), so they will not be
included with the library.
The complete listing for the type library that will be used
throughout the course of this book can be found in Appendix A. To compile the library, you need to have
MKTYPLIB in your path. MKTYPLIB takes one argument on the command
line, the name of the ODL file containing the
type library definition. To compile, simply type:
mktyplib vbshell.odl
from the command line. If everything is in order, this should produce
a file named vbshell.tlb. This is the type
library.
To use this library from Visual Basic, you should select Project ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access