フォルダのアイコンを指定

(2004.03.25)
    // フォルダのアイコンを設定
    static HRESULT SetFolderIcon(LPCTSTR szDirectoryName, LPCTSTR szIconPath, int nIconIndex = 0)
    {
        CString strDesktopIni = GetProfileFileName(szDirectoryName);
 
        // [.ShellClassInfo]
        // IconFile=
        ::WritePrivateProfileString(_T(".ShellClassInfo"), _T("IconFile"), szIconPath, strDesktopIni);
        // IconIndex=
        TCHAR szIconIndex[16];
        _ltot(nIconIndex, szIconIndex, 10);
        ::WritePrivateProfileString(_T(".ShellClassInfo"), _T("IconIndex"), szIconIndex, strDesktopIni);
 
        // 隠しファイルにする
        ::SetFileAttributes(strDesktopIni, FILE_ATTRIBUTE_HIDDEN);
        // フォルダのシェル拡張を有効にする
        ::PathMakeSystemFolder(szDirectoryName);    // SHLWAPI 4.71
 
        return S_OK;
    }
 
    static CString GetProfileFileName(LPCTSTR szDirectoryName)
    {
        CString strDirectoryName = /*CShlwapiHelper::*/PathAddBackslash(szDirectoryName);    // SHLWAPI 4.71
        CString strDesktopIni = strDirectoryName + _T("Desktop.ini");
 
        return strDesktopIni;
    }
 
    // バックスラッシュを付加する
    //  → CShlwapiHlperよりコピー
    static CString PathAddBackslash(CString strPath)
    {
        TCHAR szPath[_MAX_PATH];
        _tcscpy(szPath, strPath);
 
        ::PathAddBackslash(szPath);    // SHLWAPI 4.71
 
        return szPath;
    }
一覧に戻る
© 2003 WAC.com All Right Reserved.