MFC 创建快捷方式(学习笔记)
2010-08-09 22:15
316 查看
下面的代码不是我写的,是用的别人的源代码,这里记录下来,以便以后学习
void CFileOperateDlg::OnCreateShotcut() { //创建快捷方式 CString lpszPathLink("C:/aaa.lnk"); LPCSTR lpszPathObj="C:/aaa.txt"; LPCSTR lpszDesc="link for a txt"; CoInitialize(NULL); HRESULT hres; IShellLink* psl; // Get a pointer to the IShellLink interface. hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); if (SUCCEEDED(hres)) { IPersistFile* ppf; //设置快捷方式的目标路径,添加描述 psl->SetPath(lpszPathObj); psl->SetDescription(lpszDesc); // Query IShellLink for the IPersistFile interface for saving the // shortcut in persistent storage. hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); if (SUCCEEDED(hres)) { WCHAR wsz[MAX_PATH]; // Ensure that the string is Unicode. MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH); // TODO: Check return value from MultiByteWideChar to ensure // Save the link by calling IPersistFile::Save. hres = ppf->Save(wsz, TRUE); ppf->Release(); } psl->Release(); } // return hres; CoUninitialize(); }
相关文章推荐
- MFC 创建快捷方式(学习笔记)
- MFC 创建快捷方式的两种方法
- MFC创建桌面快捷方式
- 如何用MFC创建快捷方式
- MFC 创建快捷方式
- MFC创建快捷方式
- 如何用MFC创建快捷方式
- MFC创建快捷方式
- MFC创建桌面快捷方式
- MFC怎样创建快捷方式?
- 【框架-MFC】C++ 创建快捷方式
- VC MFC 创建桌面快捷方式
- C#创建快捷方式与添加网页到收藏夹
- WINCE 实用技巧 之 创建快捷方式详解
- 如何创建快捷方式
- 创建锁定桌面快捷方式
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- PB创建桌面快捷方式
- 两种在linux下创建应用程序快捷方式的方法
- Ubuntu10.04下Eclipse的安装及桌面快捷方式的创建