Understanding the Context Menu Interfaces
In order to add new items to the default context menu, you need to understand two important interface classes
- IContextMenu
- IShellExtInit
The other interface classes that are not very important but could be useful in your development are
- IContextMenu2
- IContextMenu3
Above interface classes have been defined in shlobj.h header file. You can find this header file in your installed Visual Studio directory.
IContextMenu interface
This interface defines 3 functions
/*
* Description:
* The method adds a text item to the Context Pop-Menu.
* Arguments:
* hmenu - handle to the context menu
*
* indexMenu - the index position at which context menu item gets inserted
*
* idCmdFirst - lowest value for new menu ID's
*
* idCmdLast - highest value for new menu ID's
*
* uFlags - parameter specifies the context of the invocation
*/
STDMETHOD
QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
/*
* Description:
* InvokeCommand is the core api that is used to
* execute the required functionality on selecting a menu-item.
* Arguments:
* lpici - Pointer to the structure CMINVOKECOMMANDINFO. This structure contains
* added information about the context menu.
*/
STDMETHOD
InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
/*
* Description:
* Called to do one of three things: Get a help string, make sure the item exists,
* and to get a language-independent string. The language-independent command name,
* or verb, is a name that can be passed to IContextMenu::InvokeCommand method.
* The help text is a description of the command that Windows Explorer displays in
* its status bar. It should be reasonably short.
* Arguments:
* idCmd - Menu item identifier offset.
*
* uType - Flags specifying the information to return.
*
* pwReserved - Reserved parameter. Applications must specify NULL when calling this method and handlers
* must ignore this parameter when called.
*
* pszName - The address of the buffer to receive the null-terminated string being retrieved.
*
* cchMax - Size of the buffer, in characters, to receive the null-terminated string.
*/
STDMETHOD
GetCommandString(UINT idCmd, UINT uType, UINT *pwReserved, LPSTR pszName, UINT cchMax)
IShellExtInit interface
This interface defines 1 function
/*
* Description:
* This method performs the necessary initializations eg property sheet extension,
* shortcut menu extension, or drag-and-drop handler. The initialization is a critical step
* needed to carry out execution of functions defined in the interface IContextMenu
* Arguments:
* pidlFolder : Defines a pointer to ITEMIDLIST structure that uniquely identifies a folder.
* For property sheet extensions, this parameter is NULL. For shortcut menu extensions, it is
* the item identifier list for the folder that contains the item whose shortcut menu is being displayed.
* For nondefault drag-and-drop menu extensions, this parameter specifies the target folder.
*
* lpdobj: Defines a pointer to an IDataObject interface object that can be used to retrieve the
* information on the objects being acted upon.
*
* hkeyProgID : The registry key for the file object or folder type.
*/
STDMETHOD(Initialize)(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY hkeyProgID);
IContextMenu2 and IContextMenu3 interface
These interfaces defines 1 function each. The functions are more less the same.
/*
* Description:
* The difference between these interfaces is that, IContextMenu2 interface processes the WM_INITMENUPOPUP, WM_MEASUREITEM and WM_DRAWITEM messages where as
* IContextMenu3 interface will process the WM_MENUCHAR Message (handle menus using keyboard).
*
* Arguments:
* uMsg - The message to be processed. In the case of some messages, such as WM_INITMENUPOPUP,
* WM_DRAWITEM, WM_MENUCHAR, or WM_MEASUREITEM, the client object being called may provide owner-drawn
* menu items.
*
* wParam - Stores additional message information. The value of this parameter depends on the value of
* the uMsg parameter.
*
* lParam - Stores additional message information. The value of this parameter depends on the value of
* the uMsg parameter.
*
* plResult - The address of an LRESULT value that the owner of the menu will return from the message.
* This parameter can be NULL.
*/
STDMETHOD(HandleMenuMsg)(UINT uMsg, WPARAM wParam, LPARAM lParam);
STDMETHOD(HandleMenuMsg2)(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* plResult);
When windows processes one the above mentioned messages you can call the HandleMenuMsg or HandleMenuMsg2 methods to handle them appropriately. These interfaces add minimum support needed for bit mapped menus especially if you are programming for cascading pop up menus as shown below
[Image1.JPG]
Comments
There are no comments yet. Be the first to comment!