Figure 4 ShellNew Key Values
Value Name | Value Data | ||
NullFile | "" | ||
FileName | Path | ||
Data | Binary data | ||
Command | Command line |
Figure 5 RFG MenuOptions
Menu Option | (Default) Value | Description | ||
edit | "&Edit" | Edit is displayed in the menu | ||
open | "Mer&ge" | Merge is displayed in the menu | ||
"" | Print is displayed in the menu |
Figure 7 Shell Extensions You Can Write
Shell Extension | Description |
Context menu handler | Adds menu options to the File and context menu for a particular data type. |
Property sheet handlers | Adds pages to the document_s property sheet. |
Icon handler | Determines which icon to display for a data type. |
Copy-hook handlers | Allows/prevents a folder/printer from being moved, copied, deleted, or renamed by the user. |
Drag-and-drop handlers | Adds menu options to the drag/drop context menu for a particular data type. |
Drop handler | Allows you to have fine control over the actions executed when file(s) are dropped on a document. |
Data handler | Allows you to have fine control over the data format used when your document file is dropped on something else. |
Figure 8 Shell Extension Subkeys
Shell Extension | Subkey | ||
Context menu handle | HKEY_CLASSES_ROOT\AppId\ShellEx\ContextMenuHandlers | ||
Property sheet handlers | HKEY_CLASSES_ROOT\AppId\ShellEx\PropertySheetHandlers | ||
Icon handler | HKEY_CLASSES_ROOT\AppId\ShellEx\IconHandler | ||
Copy-hook handlers | HKEY_CLASSES_ROOT\AppId\ShellEx\CopyHookHandlers | ||
Drag-and-drop handlers | HKEY_CLASSES_ROOT\AppId\ShellEx\DragDropHandlers | ||
Drop handler | HKEY_CLASSES_ROOT\AppId\ShellEx\DropHandler | ||
Data handler | HKEY_CLASSES_ROOT\AppId\ShellEx\DataHandler |
Figure 9 Shell Link Components
Component | Description | |
Pathname | The pathname of the object to which the shell link refers. This is usually an EXE file but it can be a folder, a data file, and so on. | |
Arguments | These are the command line arguments that are passed to the pathname when the shell link file is executed. | |
Icon pathname | This is the pathname of the file that contains the icon that is displayed when the shell link file is viewed by the Explorer. This is usually an EXE, DLL, or ICO file. | |
Icon index | This identifies which icon in the Icon pathname file should be displayed. | |
Working directory | This path identifies the initial working directory of the process that is invoked when the shell link is executed. | |
Hot key | This identifies the hot key that will automatically execute the shell link. | |
Show command | This is an SW_* identifier (defined by the ShowWindow function) that tells the new process how its main window should be displayed. This value is usually SW_ | |
SHOWNORMAL. | ||
Description | This is a description line that is associated with the shell link. It is never displayed and therefore is infrequently set. |
Figure 10 LINKDATA
#define LD_USEDESC 0x00000001
#define LD_USEARGS 0x00000002
#define LD_USEICON 0x00000004
#define LD_USEWORKDIR 0x00000008
#define LD_USEHOTKEY 0x00000010
#define LD_USESHOWCMD 0x00000020
typedef struct {
// Mandatory members
LPTSTR pszPathname; // Pathname of original object
DWORD fdwFlags; // LD_* flags ORed together for optional members
// Optional members
LPTSTR pszDesc; // Description of link file (its filename)
LPTSTR pszArgs; // command-line arguments
LPTSTR pszIconPath; // Pathname of file containing the icon
int nIconIndex; // Index of icon in pszIconPath
LPTSTR pszWorkingDir;// Working directory when process starts
int nShowCmd; // How to show the initial window
WORD wHotkey; // Hot key for the link
} LINKDATA, *PLINKDATA;
Figure 11 Shell_CreateLink
HRESULT WINAPI Shell_CreateLink (LPCTSTR pszLinkFilePathname, PLINKDATA pld) {
HRESULT hres;
IShellLink* psl;
IPersistFile* ppf;
hres = CoInitialize(NULL);
// Create a shell link object
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (PVOID *) &psl);
if (SUCCEEDED(hres)) {
// Initialize the shell link object
psl->SetPath(pld->pszPathname);
if (pld->fdwFlags & LD_USEARGS)
psl->SetArguments(pld->pszArgs);
if (pld->fdwFlags & LD_USEDESC)
psl->SetDescription(pld->pszDesc);
if (pld->fdwFlags & LD_USEICON)
psl->SetIconLocation(pld->pszIconPath, pld->nIconIndex);
if (pld->fdwFlags & LD_USEWORKDIR)
psl->SetWorkingDirectory(pld->pszWorkingDir);
if (pld->fdwFlags & LD_USESHOWCMD)
psl->SetShowCmd(pld->nShowCmd);
if (pld->fdwFlags & LD_USEHOTKEY)
psl->SetHotkey(pld->wHotkey);
// Save the shell link object on the disk
hres = psl->QueryInterface(IID_IPersistFile, (PVOID *) &ppf);
if (SUCCEEDED(hres)) {
#ifndef UNICODE
// Convert the ANSI path to a Unicode path
WCHAR szPath[_MAX_PATH] = { 0 };
MultiByteToWideChar(CP_ACP, 0, pszLinkFilePathname,
strlen(pszLinkFilePathname), szPath, adgARRAY_SIZE(szPath));
hres = ppf->Save(szPath, TRUE);
#else
hres = ppf->Save(pszLinkFilePathname, TRUE);
#endif
ppf->Release();
}
psl->Release();
}
CoUninitialize();
return(hres);
}