创建文件的快捷方式
BOOL CShell::CreateLink(CString sPathSource, CString sPathLink, CString sDescription) { return CreateLink((LPCITEMIDLIST)(LPSTR)(LPCTSTR)sPathSource, sPathLink, sDescription, TRUE); } BOOL CShell::CreateLink(LPCITEMIDLIST lpi, CString sPathLink, CString sDescription, BOOL bByName) { HRESULT hres; IShellLink * psl; //Get a pointer to the IShellLink interface. 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. if(bByName) psl->SetPath((LPSTR)lpi); else psl->SetIDList(lpi); psl->SetDescription(sDescription); // Query IShellLink for the IPersistFile interface for saving the // shortcut in persistent storage. hres = psl->QueryInterface(IID_IPersistFile, (void * *) & ppf); if (SUCCEEDED(hres)) { // Save the link by calling IPersistFile::Save. WORD wsz[MAX_PATH]; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sPathLink, -1, wsz,MAX_PATH); hres = ppf->Save(wsz, TRUE); ppf->Release(); } psl->Release(); } return SUCCEEDED(hres); }
注:转载文章需注明来源:VCer.net 文章地址:http://vcer.net/1047279673922.html
如果你觉得VCer.net不错,而且你愿意为VCer.net捐赠一元钱,那么点击后面的捐赠按钮吧:)
我得意,我用他的代码;
我自豪,他用我的代码!
void main() { printf("hello, vcer!"); }
A B C D E