创建Shortcut是使用IShellLink接口完成的,下面的代码展示了简单的创建过程<br>/*********************************<br>HRESULT hres;<br>IShellLink *psl;<br><br>// Create an IShellLink object and get a pointer to the IShellLink <br>// interface (returned from CoCreateInstance).<br>hres = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);<br>if (SUCCEEDED (hres)) {<br> IPersistFile *ppf;<br><br> // Query IShellLink for the IPersistFile interface for <br> // saving the shortcut in persistent storage.<br> hres = psl->QueryInterface (IID_IPersistFile, (void**)&ppf);<br> if (SUCCEEDED (hres)) {<br> WORD wsz [MAX_PATH]; // buffer for Unicode string<br> <br> // Set the path to the shortcut target.<br> hres = psl->SetPath (pszShortcutFile);<br> if (! SUCCEEDED (hres))<br> AfxMessageBox ("SetPath failed!");<br><br> // Set the description of the shortcut.<br> hres = psl->SetDescription (pszDesc);<br> if (! SUCCEEDED (hres))<br> AfxMessageBox ("SetDescription failed!");<br><br> // Ensure that the string consists of ANSI characters.<br> MultiByteToWideChar (CP_ACP, 0, pszLink, -1, wsz, MAX_PATH);<br> <br> // Save the shortcut via the IPersistFile::Save member function.<br> hres = ppf->Save (wsz, TRUE);<br> <br> if (! SUCCEEDED (hres))<br> AfxMessageBox (“Save failed!”);<br> <br> // Release the pointer to IPersistFile.<br> ppf->Release ();<br> }<br> <br> // Release the pointer to IShellLink.<br> psl->Release ();<br>}<br>*****************************/<br>IShellLink 支持下列方法:<br><br>GetArguments Retrieves the command-line arguments associated with a shell link object. <br>GetDescription Retrieves the description string for a shell link object. <br>GetHotkey Retrieves the hot key for a shell link object. <br>GetIconLocation Retrieves the location (path and index) of the icon for a shell link object. <br>GetIDList Retrieves the list of item identifiers for a shell link object. <br>GetPath Retrieves the path and file name of a shell link object. <br>GetShowCmd Retrieves the show (SW_) command for a shell link object. <br>GetWorkingDirectory Retrieves the name of the working directory for a shell link object. <br>Resolve Resolves a shell link by searching for the shell link object and updating the shell link path and its list of identifiers (if necessary). <br>SetArguments Sets the command-line arguments associated with a shell link object. <br>SetDescription Sets the description string for a shell link object. <br>SetHotkey Sets the hot key for a shell link object. <br>SetIconLocation Sets the location (path and index) of the icon for a shell link object. <br>SetIDList Sets the list of item identifiers for a shell link object. <br>SetPath Sets the path and file name of a shell link object. <br>SetRelativePath Sets the relative path for a shell link object. <br>SetShowCmd Sets the show (SW_) command for a shell link object. <br>SetWorkingDirectory Sets the name of the working directory for a shell link object. <br>细节可参考MSDN。