如何在快速启动栏创建快捷方式
HRESULT CreateShortcutToURL(LPCSTR pszURL, LPCSTR pszLinkFile);
 HRESULT CreateInterShortcut (LPCSTR pszURL, LPCSTR pszURLfilename,
 LPCSTR szDescription,LPCTSTR szIconFile = NULL,int nIndex = -1);
HRESULT CreateShortcutToURL(LPCSTR pszURL, LPCSTR pszLinkFile)
 {
 IUniformResourceLocator pURL=NULL; // Create an IUniformResourceLocator object
 HRESULT hRes=CoCreateInstance( CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER, IID_IUniformResourceLocator, (LPVOID)&pURL );
 if(SUCCEEDED(hRes)){
 IPersistFile*pPF=NULL; 
 hRes=pURL->SetURL(pszURL,0); 
 if(SUCCEEDED(hRes)){
 WCHAR wsz [MAX_PATH]; //buffer for Unicode string 
 // Ensure that the string consists of ANSI characters.
 MultiByteToWideChar(CP_ACP, 0, pszLinkFile, -1, wsz, MAX_PATH); hRes=pURL->QueryInterface(IID_IPersistFile, (void**)&pPF);
 if(SUCCEEDED(hRes)){ 
 //Save the shortcut via the IPersistFile::Save member function.
 hRes=pPF->Save(wsz,TRUE); // Release the pointer to IPersistFile.
 pPF->Release();
 }
 }
 //Release the pointer to IUniformResourceLocator
 pURL->Release();
 }
 return hRes;
 }
//another method c:\winnt
 //CoInitialize(NULL); 
 HRESULT CreateInterShortcut(LPCSTR pszURL, LPCSTR pszURLfilename, LPCSTR szDescription, LPCTSTR szIconFile, int nIndex)
 {
 IUniformResourceLocator *pHook;
HRESULT hres=CoCreateInstance(CLSID_InternetShortcut,NULL,CLSCTX_INPROC_SERVER,
 IID_IUniformResourceLocator,(void*)&pHook);
 if(SUCCEEDED(hres)){
 IPersistFileppf;
 IShellLink*psl;
//Query IShellLink for the IPersistFile interface for 
 hres=pHook->QueryInterface(IID_IPersistFile,(void)&ppf);
 hres=pHook->QueryInterface(IID_IShellLink,(void)&psl);
 if(SUCCEEDED(hres)){ 
 WCHAR wsz[MAX_PATH]; //buffer for Unicode string
 //Set the path to the shortcut target.
 pHook->SetURL(pszURL,0);
hres=psl->SetIconLocation(szIconFile,nIndex);
 if(SUCCEEDED(hres)){
 //Set the description of the shortcut.
 hres=psl->SetDescription(szDescription);
 if(SUCCEEDED(hres)){
 //Ensure that the string consists of ANSI characters.
 MultiByteToWideChar(CP_ACP,0,pszURLfilename,-1,wsz,MAX_PATH);
 //Save the shortcut via the IPersistFile::Save member function.
 hres=ppf->Save(wsz,TRUE);
 }
 }
//Release the pointer to IPersistFile.
 ppf->Release();
 psl->Release();
 }
//Release the pointer to IShellLink.
 pHook->Release();
 }
return hres;
 }
//HRESULT hRes = CreateShortcutToURL(“http://support.microsoft.com”,”c:\mssupport.url”);
 HRESULT hRes =CreateInterShortcut(“http://www.baidu.com/”, “d:\myblog.url”,”大星星的空间”,”c:\1.ico”,0); if (SUCCEEDED(hRes))
 {
 //do something }
文档信息
- 本文作者:zhupite
- 本文链接:https://zhupite.com/program/%E5%BF%AB%E6%8D%B7%E6%96%B9%E5%BC%8F%E6%8B%BE%E9%81%97.html
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)