change exe icon not work with multiple stage icon file.
-
hi all, i am change my exe icon its working fine with icon which have single stage icon. but if i select a icon file that have multiple size stages in icon file, icon not reflect on exe.
HANDLE handle = BeginUpdateResource(exe_file, FALSE);
char *buffer; // buffer to store raw icon data
long buffersize; // length of buffer
int hFile; // file handlehFile = open(ico_file, O_RDONLY | O_BINARY);
if (hFile == -1)
return; // if file doesn't exist, can't be opened etc.// calculate buffer length and load file into buffer
buffersize = filelength(hFile);
buffer = (char *)malloc(buffersize);
read(hFile, buffer, buffersize);
close(hFile);int icon_id=1;
UpdateResource( handle, // Handle to executable RT\_ICON, // Resource type - icon MAKEINTRESOURCE(icon\_id), // Make the id 1 MAKELANGID(LANG\_NEUTRAL, SUBLANG\_NEUTRAL), (buffer+22), // skip the first 22 bytes because this is the // icon header&directory entry (if the file // contains multiple images the directory entries // will be larger than 22 bytes buffersize-22 // length of buffer ); /////////////////////
// Again, we use this structure for educational purposes.
// The icon header and directory entries can be read from
// the file.
GROUPICON grData;icon_id=1;
// This is the header
grData.Reserved1 = 0; // reserved, must be 0
grData.ResourceType = 1; // type is 1 for icons
grData.ImageCount = 1; // number of icons in structure (1)// This is the directory entry
grData.Width = 32; // icon width (32)
grData.Height = 32; // icon height (32)grData.Colors = 0; // colors (256)
grData.Reserved2 = 0; // reserved, must be 0
grData.Planes = 2; // color planes
grData.BitsPerPixel = 32; // bit depthgrData.ImageSize = buffersize - 22; // size of image
grData.ResourceID = icon_id; // resource ID is 1
UpdateResource(
handle,
RT_GROUP_ICON,MAKEINTRESOURCE(icon\_id), // MAINICON contains information about the // application's displayed icon MAKELANGID(LANG\_NEUTRAL, SUBLANG\_NEUTRAL), &grData, // Pointer to this structure sizeof(GROUPICON) );
delete buffer; // free memory
// Perform the update, don't discard changes
// Write changes then close it.
if (!EndUpdateReso -
hi all, i am change my exe icon its working fine with icon which have single stage icon. but if i select a icon file that have multiple size stages in icon file, icon not reflect on exe.
HANDLE handle = BeginUpdateResource(exe_file, FALSE);
char *buffer; // buffer to store raw icon data
long buffersize; // length of buffer
int hFile; // file handlehFile = open(ico_file, O_RDONLY | O_BINARY);
if (hFile == -1)
return; // if file doesn't exist, can't be opened etc.// calculate buffer length and load file into buffer
buffersize = filelength(hFile);
buffer = (char *)malloc(buffersize);
read(hFile, buffer, buffersize);
close(hFile);int icon_id=1;
UpdateResource( handle, // Handle to executable RT\_ICON, // Resource type - icon MAKEINTRESOURCE(icon\_id), // Make the id 1 MAKELANGID(LANG\_NEUTRAL, SUBLANG\_NEUTRAL), (buffer+22), // skip the first 22 bytes because this is the // icon header&directory entry (if the file // contains multiple images the directory entries // will be larger than 22 bytes buffersize-22 // length of buffer ); /////////////////////
// Again, we use this structure for educational purposes.
// The icon header and directory entries can be read from
// the file.
GROUPICON grData;icon_id=1;
// This is the header
grData.Reserved1 = 0; // reserved, must be 0
grData.ResourceType = 1; // type is 1 for icons
grData.ImageCount = 1; // number of icons in structure (1)// This is the directory entry
grData.Width = 32; // icon width (32)
grData.Height = 32; // icon height (32)grData.Colors = 0; // colors (256)
grData.Reserved2 = 0; // reserved, must be 0
grData.Planes = 2; // color planes
grData.BitsPerPixel = 32; // bit depthgrData.ImageSize = buffersize - 22; // size of image
grData.ResourceID = icon_id; // resource ID is 1
UpdateResource(
handle,
RT_GROUP_ICON,MAKEINTRESOURCE(icon\_id), // MAINICON contains information about the // application's displayed icon MAKELANGID(LANG\_NEUTRAL, SUBLANG\_NEUTRAL), &grData, // Pointer to this structure sizeof(GROUPICON) );
delete buffer; // free memory
// Perform the update, don't discard changes
// Write changes then close it.
if (!EndUpdateResoLe@rner wrote:
buffer = (char *)malloc(buffersize); ... delete buffer; // free memory
let's begin with the basics: Why do you use malloc to allocate buffer and then use delete to free the memory?
-
Le@rner wrote:
buffer = (char *)malloc(buffersize); ... delete buffer; // free memory
let's begin with the basics: Why do you use malloc to allocate buffer and then use delete to free the memory?
-
hi all, i am change my exe icon its working fine with icon which have single stage icon. but if i select a icon file that have multiple size stages in icon file, icon not reflect on exe.
HANDLE handle = BeginUpdateResource(exe_file, FALSE);
char *buffer; // buffer to store raw icon data
long buffersize; // length of buffer
int hFile; // file handlehFile = open(ico_file, O_RDONLY | O_BINARY);
if (hFile == -1)
return; // if file doesn't exist, can't be opened etc.// calculate buffer length and load file into buffer
buffersize = filelength(hFile);
buffer = (char *)malloc(buffersize);
read(hFile, buffer, buffersize);
close(hFile);int icon_id=1;
UpdateResource( handle, // Handle to executable RT\_ICON, // Resource type - icon MAKEINTRESOURCE(icon\_id), // Make the id 1 MAKELANGID(LANG\_NEUTRAL, SUBLANG\_NEUTRAL), (buffer+22), // skip the first 22 bytes because this is the // icon header&directory entry (if the file // contains multiple images the directory entries // will be larger than 22 bytes buffersize-22 // length of buffer ); /////////////////////
// Again, we use this structure for educational purposes.
// The icon header and directory entries can be read from
// the file.
GROUPICON grData;icon_id=1;
// This is the header
grData.Reserved1 = 0; // reserved, must be 0
grData.ResourceType = 1; // type is 1 for icons
grData.ImageCount = 1; // number of icons in structure (1)// This is the directory entry
grData.Width = 32; // icon width (32)
grData.Height = 32; // icon height (32)grData.Colors = 0; // colors (256)
grData.Reserved2 = 0; // reserved, must be 0
grData.Planes = 2; // color planes
grData.BitsPerPixel = 32; // bit depthgrData.ImageSize = buffersize - 22; // size of image
grData.ResourceID = icon_id; // resource ID is 1
UpdateResource(
handle,
RT_GROUP_ICON,MAKEINTRESOURCE(icon\_id), // MAINICON contains information about the // application's displayed icon MAKELANGID(LANG\_NEUTRAL, SUBLANG\_NEUTRAL), &grData, // Pointer to this structure sizeof(GROUPICON) );
delete buffer; // free memory
// Perform the update, don't discard changes
// Write changes then close it.
if (!EndUpdateResoQuote:
(buffer+22), // skip the first 22 bytes because this is the // icon header&directory entry (if the file // contains multiple images the directory entries // will be larger than 22 bytes buffersize-22 // length of buffer );
The above remark is a hint, isn't it?
"In testa che avete, Signor di Ceprano?" -- Rigoletto
-
Quote:
(buffer+22), // skip the first 22 bytes because this is the // icon header&directory entry (if the file // contains multiple images the directory entries // will be larger than 22 bytes buffersize-22 // length of buffer );
The above remark is a hint, isn't it?
"In testa che avete, Signor di Ceprano?" -- Rigoletto
You beat me to it.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak
-
You beat me to it.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak