How to add verbs for ATL ActiveX controls embedded in an Office application (275862)
The information in this article applies to:
- The Microsoft Active Template Library (ATL) 3.0, when used with:
- Microsoft Visual C++, 32-bit Editions 6.0
- Microsoft Visual C++ 2005 Express Edition
- Microsoft Visual C++ .NET (2003)
- Microsoft Visual C++ .NET (2002)
This article was previously published under Q275862 Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code. Microsoft Visual C++ 2005 supported both the managed code
model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows
code model. SUMMARY When embedded in a Microsoft Office application, some
ActiveX controls add custom menu items (verbs) to the context menu. MFC
controls automatically add Edit and Properties menu items, for example. An ATL control does not do this. This
article explains how to add this feature for ATL controls. MORE INFORMATION The ATL CIRC sample essentially shows how to do this, but
there is a small problem. The options are added as verb entries in the .rgs
file, and OnDoVerb is overridden to take action based on the iVerb parameter, which is actually the menu option selected, or to do
default processing. Unfortunately, the CIRC sample sets up the menu options as
"1" and "2", which works fine in Microsoft PowerPoint, but not in Microsoft
Word. The correct setup for the menu options is 0-based, so the verb entries in
the .rgs file should look like this:
'verb'
{
'0' = s '&CircProps,0,2'
'1' = s '&Activate,0,2'
}
Then, the OnDoVerb override can be written as follows:
STDMETHOD(DoVerb)(LONG iVerb,LPMSG lpmsg, IOleClientSite *pActiveSite,
LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
{
if (iVerb == 0)
return IOleObjectImpl<CCircCtl>::DoVerb(OLEIVERB_PROPERTIES,
lpmsg, pActiveSite, lindex,
hwndParent, lprcPosRect);
if (iVerb == 1)
return IOleObjectImpl<CCircCtl>::DoVerb(OLEIVERB_SHOW, lpmsg,
pActiveSite, lindex,
hwndParent, lprcPosRect);
return IOleObjectImpl<CCircCtl>::DoVerb(iVerb, lpmsg, pActiveSite,
lindex, hwndParent, lprcPosRect);
}
REFERENCES The ATL Circ sample is located in the ATL samples folder on
the MSDN Library CD-ROM. A link is provided on the documentation page for the
sample, titled "CIRC: Demonstrates Using Property Pages". It is also available
on the MSDN Online Web site: For more information on implementing the DoVerb method of IOleObject, see the documentation page IOleObject::DoVerb in the Platform SDK Documentation. The OLEIVERB_XXX enumerations
are explained here (except OLEIVERB_PROPERTIES). All other enumerations are
defined in ole2.h; OLEIVERB_PROPERTIES is defined separately in
olectl.h.
Modification Type: | Major | Last Reviewed: | 1/12/2006 |
---|
Keywords: | kbCtrl kbhowto KB275862 kbAudDeveloper |
---|
|