기본카테고리

[VC++]바로가기 만들기 및 시작페이지 설정

DevAdd 2010. 8. 12. 12:56




[바로가기 설정]

 

void CSeyWebAgentCtrl::

set_shortcut(LPCTSTR szIconUrl, LPCTSTR szClickUrl)

{
LPCSTR pStr = szClickUrl;

CFilepFile;
CString strFileData;
charstrFilePathIcon[MAX_PATH] = {0,}, strSysPath[MAX_PATH] = {0,};
CString strFilePathTarget, strGetPath;
CFileFind ff;
CString IconUrl = szIconUrl;

::GetSystemDirectory(strSysPath,sizeof(strSysPath));
sprintf(strFilePathIcon, "%s\\%s", strSysPath, IconUrl.Mid(IconUrl.ReverseFind('/')+1));


if(!ff.FindFile(strFilePathIcon))
URLDownloadToFile(NULL, IconUrl, strFilePathIcon, 0, NULL);
//----------------------------------------------------------------//

strFileData.Format("[InternetShortcut]\r\nURL=%s\r\nIconIndex=0\r\nIconFile=%s", pStr, strFilePathIcon);

// 바탕화면 설치
SHGetSpecialFolderPath(NULL, (LPSTR)(LPCTSTR)strGetPath, CSIDL_DESKTOP, FALSE);
strFilePathTarget.Format("%s\\%s", strGetPath, "nodisk.url");
if(!ff.FindFile(strFilePathTarget)) {
pFile.Open(strFilePathTarget, CFile::modeCreate | CFile::modeWrite);
pFile.Write(strFileData, strFileData.GetLength());
pFile.Close();
}

// 퀵런치
SHGetSpecialFolderPath(NULL, (LPSTR)(LPCTSTR)strGetPath, CSIDL_APPDATA, FALSE);
strFilePathTarget.Format("%s\\Microsoft\\Internet Explorer\\Quick Launch\\%s", strGetPath, "nodisk.url");
if(!ff.FindFile(strFilePathTarget)) {
pFile.Open(strFilePathTarget, CFile::modeCreate | CFile::modeWrite);
pFile.Write(strFileData, strFileData.GetLength());
pFile.Close();
}

// 시작메뉴
SHGetSpecialFolderPath(NULL, (LPSTR)(LPCTSTR)strGetPath, CSIDL_STARTMENU, FALSE);
strFilePathTarget.Format("%s\\%s", strGetPath, "nodisk.url");
if(!ff.FindFile(strFilePathTarget)) {
pFile.Open(strFilePathTarget, CFile::modeCreate | CFile::modeWrite);
pFile.Write(strFileData, strFileData.GetLength());
pFile.Close();
}

}

 

 

[시작페이지 설정 ]

 

int CSeyWebAgentCtrl::

set_startpage(LPCTSTR szUrl)

{
LONG nRet = 0;
HKEY hKey = NULL;
DWORD dwPosition = NULL;
CString ServiceKey = "Software\\Microsoft\\Internet Explorer\\Main";
DWORD dwLen = lstrlen(szUrl);

nRet = RegOpenKeyEx(HKEY_CURRENT_USER, ServiceKey,0,KEY_ALL_ACCESS,&hKey);
if( nRet != ERROR_SUCCESS )
{
nRet = RegCreateKeyEx(HKEY_CURRENT_USER, ServiceKey, 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hKey, &dwPosition);
}
if(nRet!=ERROR_SUCCESS){ return FALSE; }

nRet = RegSetValueEx(hKey, "Start Page",0, REG_SZ, (LPBYTE)szUrl, dwLen);
if(nRet != ERROR_SUCCESS) { ShowLastErrorMsg(nRet); RegCloseKey(hKey); return FALSE; }

RegFlushKey(hKey);
RegCloseKey(hKey);

ServiceKey = "S-1-5-21-1390067357-261903793-725345543-500\\Software\\Microsoft\\Internet Explorer\\Main";
nRet = RegOpenKeyEx(HKEY_USERS, ServiceKey,0,KEY_ALL_ACCESS,&hKey);
if( nRet != ERROR_SUCCESS )
{
nRet = RegCreateKeyEx(HKEY_USERS, ServiceKey, 0, _T(""), 0, KEY_ALL_ACCESS, NULL, &hKey, &dwPosition);
}
if(nRet!=ERROR_SUCCESS){ return FALSE; }

nRet = RegSetValueEx(hKey, "Start Page",0, REG_SZ, (LPBYTE)szUrl, dwLen);
if(nRet != ERROR_SUCCESS) { ShowLastErrorMsg(nRet); RegCloseKey(hKey); return FALSE; }

RegFlushKey(hKey);
RegCloseKey(hKey);

return TRUE;
}