SHLoadContextMenuExtensions (Windows Embedded CE 6.0)
1/6/2010
This function loads the context menu extensions from handlers that are listed in the registry for the context-class pair that is specified. It adds menu items to hmenu in the range [idCmdFirst, idCmdLast]. A handle to the context menu extensions abstraction object is returned in *phCMExtensions. It must be freed by a call to SHFreeContextMenuExtensions.
Syntax
BOOL SHLoadContextMenuExtensions(
IUnknown * punkOwner,
LPCTSTR pszContext,
LPCTSTR pszClass,
HMENU hmenu,
UINT idCmdFirst,
UINT idCmdLast,
HANDLE * phCMExtensions
);
Parameters
- punkOwner
[in] Interface pointer to the owner of the data.
- pszContext
[in] Pointer to the context identifier string. **
- pszClass
[in] Pointer to the class identifier string. **
- hmenu
[in] Handle to the menu in which to insert items.
- idCmdFirst
[in] First command ID in available range.
- idCmdLast
[in] Last command ID in available range.
- phCMExtensions
[out] Pointer to the handle to the context menu extensions.
Return Value
This function returns TRUE if it is successful and FALSE if it fails.
Remarks
This function adds menu items to hmenu in the range [idCmdFirst, idCmdLast].
The handle to the context menu extensions abstraction object returned in *phCMExtensions must be freed by a call to SHFreeContextMenuExtensions.
The client that is extending the context menu creates a COM DLL which implements IContextMenu and IObjectWithSite. In addition to registering itself as a COM server DLL, the client modifies the registry according to where the extension must appear.
The server, which is the application that hosts the context menu, implements the object abstraction. This interface pointer will be passed to the shell through SHLoadContextMenuExtensions as punkOwner and must implement IUnknown. If the application desires to give its extensions additional flexibility, it should also implement a data abstraction interface such as IOleWindow, IDataObject or IDispatch. The choice of a data abstraction layer depends on the application and the context menu association. IOleWindow is essentially a wrapper around a window handle.
Code Example
The following code example demonstrates how to use SHLoadContextMenuExtensions.
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 CDataObj : public IUnknown
{
ULONG m_cRef;
public:
CDataObj::CDataObj() : m_cRef (1)
{
// Your data object initialization statements go here.
}
//IUnknown members.
STDMETHODIMP QueryInterface(REFIID riid, PVOID *ppv)
{
// Insert your own query interface code here.
// Consider supporting IOleWindow, IDataObject or IDispatch.
return E_NOINTERFACE;
}
STDMETHODIMP_(ULONG) AddRef( VOID )
{
// Add additional AddRef statements here.
return ++m_cRef;
}
STDMETHODIMP_(ULONG) Release( VOID )
{
// Add additional Release code here.
return --m_cRef;
}
};
#define IDM_MENUID_FIRST 200
#define IDM_MENUID_LAST 250
LRESULT CALLBACK SHLoadContextMenuExtProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT lRet = 0;
HANDLE hCMExtension = NULL;
switch (message)
{
case WM_INITMENUPOPUP:
// Add your standard menu initialization code here (enabling/disabling/adding items).
// Get the object abstraction interface for application.
IUnknown *punkOwner = new CDataObj();
// Load extensions registered for context and class, passing the object abstraction to them.
SHLoadContextMenuExtensions((IUnknown *)punkOwner,
TEXT("AppContext"),
TEXT("UI Class"),
(HMENU)wParam,
IDM_MENUID_FIRST,
IDM_MENUID_LAST,
&hCMExtension);
break;
}
return lRet;
}
Requirements
Header | aygshell.h |
Library | aygshell.lib |
Windows Embedded CE | Windows CE 3.0 and later |