Freigeben über


How to Implement IContextMenu and IObjectWithSite

4/19/2010

The following C++ code snippet demonstrates the structure of the shortcut menu extension component class definition.

Code Example

The following code example demonstrates how to implement IContextMenu and IObjectWithSite.

Note

To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.

class CMyComp : public IContextMenu, IObjectWithSite
{
    public:
        CMyComp();   // Constructor.
        ~CMyComp();  // Destructor.

        // IUnknown methods.
        STDMETHOD (QueryInterface) (REFIID riid, LPVOID *ppv);
        STDMETHOD_(ULONG, AddRef)  (void);
        STDMETHOD_(ULONG Release)  (void);

        // IContextMenu methods.
        STDMETHOD (GetCommandString) (UINT idCmd, UINT uFlags,
                   UINT *pwReserved,LPSTR pszName, UINT cchMx);
        STDMETHOD (InvokeCommand)    (LPCMINVOKECOMMANDINFO pici);
        STDMETHOD (QueryContextMenu) (hmenu, UINT indexMenu,
                   UINT idCmdFirs, UINT idCmdLast, UINT uFlags);

        // IObjectWithSite methods.
        STDMETHOD (GetSite) (REFIID riid, void **ppvSite);
        STDMETHOD (SetSite) (IUnknown *pUnkSite);

        // CMyComp methods.
        // None.

    protected:
        ULONG    m_cRef;       // Reference count.
        IUnknown m_punkSite;   // Site (owner) pointer.
};

See Also

Tasks

How to Extend Shortcut Menus

Concepts

How to Implement IDataObject
How to Register a File System Shortcut Menu
Menu Overview

Other Resources

Developing Menu Components