Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. change exe icon not work with multiple stage icon file.

change exe icon not work with multiple stage icon file.

Scheduled Pinned Locked Moved C / C++ / MFC
performanceannouncementlearning
6 Posts 5 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Le rner
    wrote on last edited by
    #1

    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 handle

    hFile = 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 depth

    grData.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

    V C 2 Replies Last reply
    0
    • L Le rner

      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 handle

      hFile = 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 depth

      grData.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

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      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?

      J 1 Reply Last reply
      0
      • V Victor Nijegorodov

        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?

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        To make life more exciting?

        1 Reply Last reply
        0
        • L Le rner

          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 handle

          hFile = 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 depth

          grData.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

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          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

          D 1 Reply Last reply
          0
          • C CPallini

            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

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            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

            C 1 Reply Last reply
            0
            • D 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

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              :) Thank you!

              "In testa che avete, Signor di Ceprano?" -- Rigoletto

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups