创建快捷方式(SHGetSpecialFolderLocation,SHGetPathFromIDList,CoCreateInstance,QueryInterface) LPITEMIDLIST pidl;
// LPMALLOC pShellMalloc;
const int nFolder[2]={ CSIDL_DESKTOPDIRECTORY,CSIDL_STARTMENU };// if(SUCCEEDED(SHGetMalloc(&pShellMalloc)))
// {
char Path[MAX_PATH+1];
for(int i=0;i<2;i++)
{
if( SUCCEEDED( SHGetSpecialFolderLocation(NULL,nFolder[i],&pidl) ) )
{
if(SHGetPathFromIDList(pidl, Path))
{
if(i==0)
m_strDesktopPath=Path;
else
m_strStartMenuPath=Path;
}
// pShellMalloc->Free(pidl);
}
}
// pShellMalloc->Release();
// }
CString str;
if(m_nType == 0)
str=m_strDesktopPath;
else
str=m_strStartMenuPath;
CFile file;
file.Open(m_strFileName,CFile::modeRead);
str+="\\";
str += file.GetFileTitle();
str += ".lnk";
file.Close(); if( CreateShortCut(m_strFileName,str) )
::AfxMessageBox("创建快捷方式成功!",MB_OK);
else
::AfxMessageBox("创建快捷方式失败!",MB_OK);////////////////////////////////////////////////////////////////////////////
// Function: create link file name
// Input  ---- strSrcPath:     source full file path name
//        strPathLink:     created link full file path name
// Output ----  BOOL value.
BOOL CreateShortCut(const CString strSrcPath,const CString strPathLink)
{
BOOL bRet = FALSE;
IShellLink* psl; if(SUCCEEDED( CoCreateInstance(CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,
IID_IShellLink,(LPVOID*) &psl))
)
{
IPersistFile* ppf;
psl->SetPath(strSrcPath);
psl->SetDescription("Shortcut");
psl->SetShowCmd(SW_SHOW); if (SUCCEEDED(psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf)))
{ WORD wsz[MAX_PATH];
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, strPathLink, 
-1, wsz,MAX_PATH);
if ( SUCCEEDED ( ppf->Save(wsz, TRUE) ) )
bRet = TRUE;
ppf->Release();
}
psl->Release();
}
return bRet;
}