BOOL CreateFileShortcut(LPCWSTR lpszFileName, LPCWSTR lpszLnkFileDir, LPCWSTR lpszLnkFileName, LPCWSTR lpszWorkDir, WORD wHotkey, LPCWSTR lpszDescription, int iShowCmd = SW_SHOWNORMAL)
{
if (lpszLnkFileDir == NULL)
return FALSE;
HRESULT hr;
IShellLink *pLink; //IShellLink对象指针
IPersistFile *ppf; //IPersisFil对象指针
//创建IShellLink对象
hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pLink);
if (FAILED(hr))
return FALSE;
//从IShellLink对象中获取IPersistFile接口
hr = pLink->QueryInterface(IID_IPersistFile, (void**)&ppf);
if (FAILED(hr))
{
pLink->Release();
return FALSE;
}
wchar_t *path;
_get_wpgmptr(&path);
pLink->SetPath(L"D://");
pLink->SetArguments(L"D:\\项目\\雷霆之怒2(0326)\\雷霆2\\贪玩雷霆之怒3.exe");
pLink->SetIconLocation(L"E:\\vs2008项目\\testlogin\\testlogin\\res\\app.ico",0);
//工作目录
if (lpszWorkDir != NULL)
pLink->SetPath(lpszWorkDir);
//快捷键
if (wHotkey != 0)
pLink->SetHotkey(wHotkey);
//备注
if (lpszDescription != NULL)
pLink->SetDescription(lpszDescription);
//显示方式
pLink->SetShowCmd(iShowCmd);
//快捷方式的路径 + 名称
//char szBuffer[MAX_PATH];
CString strLnk;
strLnk.Format(_T("%s\\%s"),lpszLnkFileDir, lpszLnkFileName);
hr = ppf->Save(strLnk, TRUE);
ppf->Release();
pLink->Release();
return SUCCEEDED(hr);
}
BOOL GetDesktopPath(wchar_t *pszDesktopPath)
{
LPITEMIDLIST ppidl = NULL;
if (SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &ppidl) == S_OK)
{
BOOL flag = SHGetPathFromIDList(ppidl, pszDesktopPath);
CoTaskMemFree(ppidl);
return flag;
}
}
{
if (lpszLnkFileDir == NULL)
return FALSE;
HRESULT hr;
IShellLink *pLink; //IShellLink对象指针
IPersistFile *ppf; //IPersisFil对象指针
//创建IShellLink对象
hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pLink);
if (FAILED(hr))
return FALSE;
//从IShellLink对象中获取IPersistFile接口
hr = pLink->QueryInterface(IID_IPersistFile, (void**)&ppf);
if (FAILED(hr))
{
pLink->Release();
return FALSE;
}
wchar_t *path;
_get_wpgmptr(&path);
pLink->SetPath(L"D://");
pLink->SetArguments(L"D:\\项目\\雷霆之怒2(0326)\\雷霆2\\贪玩雷霆之怒3.exe");
pLink->SetIconLocation(L"E:\\vs2008项目\\testlogin\\testlogin\\res\\app.ico",0);
//工作目录
if (lpszWorkDir != NULL)
pLink->SetPath(lpszWorkDir);
//快捷键
if (wHotkey != 0)
pLink->SetHotkey(wHotkey);
//备注
if (lpszDescription != NULL)
pLink->SetDescription(lpszDescription);
//显示方式
pLink->SetShowCmd(iShowCmd);
//快捷方式的路径 + 名称
//char szBuffer[MAX_PATH];
CString strLnk;
strLnk.Format(_T("%s\\%s"),lpszLnkFileDir, lpszLnkFileName);
hr = ppf->Save(strLnk, TRUE);
ppf->Release();
pLink->Release();
return SUCCEEDED(hr);
}
BOOL GetDesktopPath(wchar_t *pszDesktopPath)
{
LPITEMIDLIST ppidl = NULL;
if (SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &ppidl) == S_OK)
{
BOOL flag = SHGetPathFromIDList(ppidl, pszDesktopPath);
CoTaskMemFree(ppidl);
return flag;
}
}