53 struct GRPICONDIRENTRY
80 size_t GetImageCount()
const
82 return m_iconDir.idCount;
86 BYTE* GetImageData(INDEX index)
88 ASSERT( index < GetImageCount());
89 return m_iconImages[index].
Ref();
93 DWORD GetImageSize(INDEX index)
const
95 ASSERT(index < GetImageCount());
96 return m_iconEntrys[index].dwBytesInRes;
100 bool Load(LPCTSTR pszFileName)
103 HANDLE hFile = ::CreateFile(pszFileName, GENERIC_READ,
104 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
105 bool r = (hFile != INVALID_HANDLE_VALUE);
108 r &= !! ::ReadFile(hFile, &m_iconDir,
sizeof(ICONDIR), &dwRead, NULL);
109 ASSERT( m_iconDir.idReserved == 0 );
110 ASSERT( m_iconDir.idType == 1 );
111 ASSERT( m_iconDir.idCount > 0 );
113 m_iconEntrys.
Resize(m_iconDir.idCount);
114 loop ( i, m_iconDir.idCount )
116 r &= !! ::ReadFile(hFile, &(m_iconEntrys[i]),
sizeof(ICONDIRENTRY), &dwRead, NULL);
119 m_iconImages.
Resize(m_iconDir.idCount);
120 loop ( i, m_iconDir.idCount )
122 ::SetFilePointer(hFile, m_iconEntrys[i].dwImageOffset, NULL, FILE_BEGIN);
123 m_iconImages[i].
Resize(m_iconEntrys[i].dwBytesInRes);
124 r &= !! ::ReadFile(hFile, m_iconImages[i], m_iconEntrys[i].dwBytesInRes, &dwRead, NULL);
126 ::CloseHandle(hFile);
131 size_t SizeOfIconGroupData()
const
133 return sizeof(ICONDIR) +
sizeof(GRPICONDIRENTRY) * GetImageCount();
137 BYTE* CreateIconGroupData(
int nBaseID)
140 m_iconGroupData.
Resize(SizeOfIconGroupData());
142 memcpy(m_iconGroupData, &m_iconDir,
sizeof(ICONDIR));
143 int offset =
sizeof(ICONDIR);
144 loop ( i, GetImageCount() )
146 GRPICONDIRENTRY grpEntry;
148 BITMAPINFOHEADER bitmapheader;
149 memcpy(&bitmapheader, GetImageData(i),
sizeof(BITMAPINFOHEADER));
151 grpEntry.bWidth = m_iconEntrys[i].bWidth;
152 grpEntry.bHeight = m_iconEntrys[i].bHeight;
153 grpEntry.bColorCount = m_iconEntrys[i].bColorCount;
154 grpEntry.bReserved = m_iconEntrys[i].bReserved;
155 grpEntry.wPlanes = bitmapheader.biPlanes;
156 grpEntry.wBitCount = bitmapheader.biBitCount;
157 grpEntry.dwBytesInRes = m_iconEntrys[i].dwBytesInRes;
158 grpEntry.nID =
static_cast<WORD
>(nBaseID + i);
160 memcpy(m_iconGroupData.
Ref() + offset, &grpEntry,
sizeof(GRPICONDIRENTRY));
161 offset +=
sizeof(GRPICONDIRENTRY);
163 return m_iconGroupData.
Ref();
186 bool m_Close(
bool isDiscard)
189 if ( m_hUpdate != NULL )
191 r = !! ::EndUpdateResource(m_hUpdate, isDiscard);
216 return m_hUpdate != NULL;
227 bool Open(LPCTSTR lpszFile,
bool isDeleteExistingResources =
false)
230 m_hUpdate = ::BeginUpdateResource(lpszFile, isDeleteExistingResources);
241 return m_Close(
false);
252 bool ModifyIcon(UINT resourceId, LPCTSTR lpszIconFile, WORD wLanguage = 0)
258 r = iconFile.Load(lpszIconFile);
260 r &= !! ::UpdateResource
262 m_hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(resourceId), wLanguage,
263 iconFile.CreateIconGroupData(resourceId),
ToDword(iconFile.SizeOfIconGroupData())
266 loop ( i, iconFile.GetImageCount() )
268 r &= !! ::UpdateResource
270 m_hUpdate, RT_ICON, MAKEINTRESOURCE(resourceId+i), wLanguage,
271 iconFile.GetImageData(i), iconFile.GetImageSize(i)
#define loop(VAR, CNT)
loop構文.
CResourceUpdater(void)
コンストラクタ
bool ModifyIcon(UINT resourceId, LPCTSTR lpszIconFile, WORD wLanguage=0)
[変更] アイコン変更
bool IsValid(void) const
[確認] 有効か
bool WritePush(void)
[設定] 書き込み
bool Open(LPCTSTR lpszFile, bool isDeleteExistingResources=false)
[設定] オープン
~CResourceUpdater(void)
デストラクタ
void Resize(size_t l)
[設定] サイズ再設定
const TYP * Ref(void) const
[取得] ポインタ取得
DWORD ToDword(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
void Zero(V &value)
[設定] ゼロクリア.