C++ 創(chuàng)建桌面快捷方式 開始菜單的實現(xiàn)代碼
void CInstall_ProgressDlg::CreateShortCut(CString csLinkPath, CString csExePath, CString csIconPath)
{
HRESULT hres;
hres = ::CoInitialize(NULL);
if(S_OK == hres)
{
//delete old link
CFileFind cfind;
if(cfind.FindFile(csLinkPath)){
CFile::Remove(csLinkPath);
}
IShellLink * pShellLink ;
hres = ::CoCreateInstance( CLSID_ShellLink, NULL,CLSCTX_INPROC_SERVER, IID_IShellLink,(void **)&pShellLink);
if( SUCCEEDED( hres))
{
pShellLink -> SetPath(csExePath);
if(PathFileExists(csIconPath))
pShellLink -> SetIconLocation(csIconPath, 0);
pShellLink -> SetHotkey( MAKEWORD( 'R', HOTKEYF_SHIFT | HOTKEYF_CONTROL));
CString csWorkingDir;
csWorkingDir = csExePath.Left(2);
csWorkingDir.Append(FILE_SEPARATOR);
TRACE_CS(csWorkingDir);
pShellLink -> SetWorkingDirectory(csWorkingDir);
IPersistFile *pPersistFile;
hres = pShellLink -> QueryInterface( IID_IPersistFile, (void **)&pPersistFile) ;
if( SUCCEEDED(hres))
{
hres = pPersistFile -> Save(csLinkPath, TRUE);
pPersistFile -> Release();
}
pShellLink -> Release();
}
::CoUninitialize();
}
}
void CInstall_ProgressDlg::CreateStartMenu()
{
TCHAR chStartupFolder[MAX_PATH];
/*
*parm1: hwnd
*parm2: path buffer
*parm3: CSIDL_PROGRAMS 0x0002 / Start Menu\Programs
*parm4: true:if file !exist to create, false:not create
*/
SHGetSpecialFolderPath(this->GetSafeHwnd(), chStartupFolder,CSIDL_PROGRAMS,FALSE);
CString csStartupFolder = chStartupFolder;
csStartupFolder.Append(FILE_SEPARATOR);
csStartupFolder.Append(FOLDER_APP_NAME);
if(!PathFileExists(csStartupFolder)){
g_InstallHelper.CreateInstallFolder(csStartupFolder);
}
CString csInstallPath;
csInstallPath = g_InstallInfo.chInstallPath;
CString csEXEFilePath;
csEXEFilePath = csInstallPath;
csEXEFilePath.Append(FILE_SEPARATOR);
csEXEFilePath.Append(FILE_APP_NAME);
CString csUnExeFilePath;
csUnExeFilePath = csInstallPath;
csUnExeFilePath.Append(FILE_SEPARATOR);
csUnExeFilePath.Append(FILE_UNINSTALL_NAME);
CString csLinkFileName = csStartupFolder;
csLinkFileName.Append(FILE_SEPARATOR);
csLinkFileName.Append(LINK_NAME);
csLinkFileName.Append(LINK_EXT);
CString csUnlinkFileName = csStartupFolder;
csUnlinkFileName.Append(FILE_SEPARATOR);
csUnlinkFileName.Append(LINK_UNINSTALL_NAME);
csUnlinkFileName.Append(LINK_EXT);
//get icon path
CString csExeIconPath;
csExeIconPath = csInstallPath;
csExeIconPath.Append(FILE_SEPARATOR);
csExeIconPath.Append(ICON_APP_EXE_NAME);
CString csUnExeIconPath;
csUnExeIconPath = csInstallPath;
csUnExeIconPath.Append(FILE_SEPARATOR);
csUnExeIconPath.Append(ICON_UNINSTALL_EXE_NAME);
TRACE_CS(csLinkFileName);
TRACE_CS(csEXEFilePath);
TRACE_CS(csExeIconPath);
TRACE_CS(csUnlinkFileName);
TRACE_CS(csUnExeFilePath);
TRACE_CS(csUnExeIconPath);
CreateShortCut(csLinkFileName, csEXEFilePath, csExeIconPath);
CreateShortCut(csUnlinkFileName, csUnExeFilePath, csUnExeIconPath);
}
相關(guān)文章
CreateThread()與beginthread()的區(qū)別詳細解析
很多開發(fā)者不清楚這兩者之間的關(guān)系,他們隨意選一個函數(shù)來用,發(fā)現(xiàn)也沒有什么大問題,于是就忙于解決更為緊迫的任務(wù)去了。等到有一天忽然發(fā)現(xiàn)一個程序運行時間很長的時候會有細微的內(nèi)存泄露,開發(fā)者絕對不會想到是因為這兩套函數(shù)用混的結(jié)果2013-09-09標(biāo)準(zhǔn)C++類string的Copy-On-Write技術(shù)
這里,我想從C++類或是設(shè)計模式的角度為各位揭開Copy-On-Write技術(shù)在string中實現(xiàn)的面紗,以供各位在用C++進行類庫設(shè)計時做一點參考2013-11-11