~~Title: Context and Drop Menus~~
When the user clicks the right button on a file in your namespace, or drags a file with the right button into your namespace, Opus calls functions in your plugin to build a context menu for display to the user. The two functions responsible for this are [[:reference:plugins:vfs_plugins:vfs_getcontextmenu|VFS_GetContextMenu]] and [[:reference:plugins:vfs_plugins:vfs_getdropmenu|VFS_GetDropMenu]] and they are very similar.
BOOL VFS_GetContextMenu( HANDLE hVFSData, LPVFSFUNCDATA lpFuncData,
LPTSTR lpszFiles,
LPVFSCONTEXTMENUDATA lpMenuData )
**hVFSData** is your namespace instance handle, and **lpFuncData** is currently unused. **lpszFiles** is a double null-terminated list of files, providing the full pathnames of the files the user right-clicked on. **lpMenuData** points to a **VFSCONTEXTMENUDATA** structure.
By comparison, the [[:reference:plugins:vfs_plugins:vfs_getdropmenu|VFS_GetDropMenu]] function is almost identical:
BOOL VFS_GetDropMenu( HANDLE hVFSData, LPVFSFUNCDATA lpFuncData,
LPTSTR lpszFiles,
LPVFSCONTEXTMENUDATA lpMenuData,
DWORD dwEffects )
The only addition to this function definition is the **dwEffects** parameter which is a mask of the OLE drag-and-drop "effects" currently in use when the drop occurred (that is, **DROPEFFECT_COPY** indicates the control key was held down, **DROPEFFECT_MOVE** indicates the shift key and **DROPEFFECT_LINK** indicates the alt key. **DROPEFFECT_NONE** indicates no qualifier keys were held down when the drop occurred.)
The **VFSCONTEXTMENUDATA** structure is defined as follows:
* **UINT cbSize** \\ This will be set to the size of the **VFSCONTEXTMENUDATA** structure that Opus is using. This is to maintain compatibility with older versions of the API. You should only access fields up to and including the size of this structure.
* **BOOL fAllowContextMenu** \\ Set this to **FALSE** to disallow this context menu, or **TRUE** to allow it.
* **BOOL fDefaultContextMenu** \\ Set this to **TRUE** to have Opus include default context menu items in the context menu shown to the user. Any items you provide will be displayed either above or below the default items. If you set this to **FALSE** then only the items you provide will be displayed.
* **BOOL fCustomItemsBelow** \\ Set this to **TRUE** to have your custom items displayed below the default ones, or **FALSE** to have your items displayed above them. Has no effect if **fDefaultContextMenu** is set to **FALSE**.
* **LPVFSCONTEXTMENUITEM lpCustomItems** \\ Set this value to point to an array of **VFSCONTEXTMENUITEM** structures, one for each custom item you wish to add to the context menu. The array can either by statically defined in your plugin, or you can allocate it at run-time using **LocalAlloc**. If you choose to allocate the menu array at run-time you must set the **fFreeCustomItems** flag to enable Opus to free the array via **LocalFree** once it has displayed the context menu.
* **int iNumCustomItems** \\ Set this field to the number of **VFSCONTEXTMENUITEM** structures in the array provided by **lpCustomItems**.
* **BOOL fFreeCustomItems** \\ Set this value to **TRUE** to have Opus free your **lpCustomItems** array via **LocalFree** once the context menu has been displayed. If you set this to **FALSE** Opus will not free your array.
The **lpCustomItems** member points to an array of **VFSCONTEXTMENUITEM** structures that you supply. This structure is defined as follows:
* **UINT cbSize** \\ You must set this field to the size of the **VFSCONTEXTMENUITEM** structure you are using (that is, sizeof(VFSCONTEXTMENUITEM).) Opus uses this value to iterate through the array you provide.
* **DWORD dwFlags** \\ This is a flags field that controls the behavior and appearance of the menu item. The currently defined flags are:
|VFSCMF_CHECKED|displays a checkmark next to the menu item|
|VFSCMF_RADIOCHECK|the checkmark is displayed as a radio button|
|VFSCMF_DISABLED|the item is disabled and cannot be selected|
|VFSCMF_SEPARATOR|the item is a separator bar|
|VFSCMF_BEGINSUBMENU|the item begins a submenu|
|VFSCMF_ENDSUBMENU|the item is the last in a submenu|
* **LPTSTR lpszLabel** \\ This points to a string that is the label of the context menu item. To assign a hotkey to a menu item prefix the letter with an ampersand (&) character.
* **LPTSTR lpszCommand** \\ This is the command string that will be executed if the user chooses this menu item.
Note that if you set the **fFreeCustomItems** flag to **TRUE** to have Opus free the menu item array, only the memory pointed to by **lpCustomItems** is freed - the individual strings in each **VFSCONTEXTMENUITEM structure** are not. Therefore the strings must either be statically defined in your plugin, or must be part of the memory chunk that you allocated for **lpCustomItems**. Otherwise you may leak memory when the user displays your context menu.
The command string pointed to by **lpszCommand** defines the command that is executed when the user chooses that menu item. This can be any raw Opus command (for example, **"Go OPENINDUAL"**) or it can be a user-defined command verb. To specify your own commands, select a verb keyword and prefix it with a $ character. This verb (minus the leading $ character) will be passed to your [[:reference:plugins:vfs_plugins:vfs_contextverb|VFS_ContextVerb]] function when the user selects this command from the context menu. For example, a context menu item whose **lpszCommand** string was set to **"$viewfile"** would trigger a call to [[:reference:plugins:vfs_plugins:vfs_contextverb|VFS_ContextVerb]] with the **lpszVerb** parameter set the **"viewfile"**.
If you do not want to add your own context menu items and simply want Opus to display default context menus, you do not need to provide the context menu functions.