搞到了。谢谢!!!
Windows外壳(Shell)的快捷方式是以OLE技术的组件对象模型
COM(Component Object Modal)为基础而设计的。利用COM模型,一个应用程
序可以调用另一应用程序的某些功能。这方面的技术细节请参阅有关文献。
在了解了上述基本原理后,创建Windows的快捷方式就比较容易了。首先利
用OLE通过调用CoCreateInstance()函数建立一个IID_IShellLink实例,并同
时得到其接口指针。利用这个接口指针可以对其各项属性进行设置。为了使这
些信息以快捷方式的数据文件(*.lnk)格式保存起来,还需要从IID_IShellLink
http://www.cnnic-qd.cn/it/index.html
对象取得其IID_IPersistFile接口指针,以便于调用其成员函数Save()保存前面
设置的信息。
至于如何删除快捷方式以及创建和删除文件夹,则只需要简单地调用文件操作
函数SHFileOperation()就可以了。
另外应该注意,在完成上述操作之后,都要调用SHChangeNotify()函数通
知Windows外壳有关变化以使之及时更新其显示状态。
---------------------------------------------------------------
创建快捷方式
HRESULT CreateLink(LPCSTR lpszPathObj,
LPSTR lpszPathLink,
LPSTR lpszDesc)
{
HRESULT hres;
IShellLink* psl;
CoInitialize(NULL);
// Get a pointer to the IShellLink interface.
http://www.cnnic-qd.cn/it/index.html
hres = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(void **)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
// Set the path to the shortcut target and add the
// description.
psl->SetPath(lpszPathObj);
psl->SetDescription(lpszDesc);
// Query IShellLink for the IPersistFile interface for saving the
IT教程:
http://www.cnnic-qd.cn/it/index.html
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
if (SUCCEEDED(hres))
{
WORD wsz[MAX_PATH]; // Ensure that the string is ANSI.
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1,wsz, MAX_PATH);
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(wsz, TRUE);
ppf->Release();
http://www.cnnic-qd.cn/it/index.html
}
psl->Release();
}
return hres;
}