Microsoft KB Archive/275862

= How to add verbs for ATL ActiveX controls embedded in an Office application =

Article ID: 275862

Article Last Modified on 1/12/2006

-

APPLIES TO

 Microsoft ActiveX Template Library 3.0, when used with:  Microsoft Visual C++ 6.0 Service Pack 5

 Microsoft Visual C++ 2005 Express Edition

 Microsoft Visual C++ .NET 2003 Standard Edition

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q275862

<div class="notice_section">

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.

<div class="summary_section">

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.

<div class="moreinformation_section">

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 &quot;1&quot; and &quot;2&quot;, 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); }

<div class="references_section">