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. problem in updating the icon

problem in updating the icon

Scheduled Pinned Locked Moved C / C++ / MFC
helpannouncementlearning
5 Posts 3 Posters 0 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
    learningvisualc
    wrote on last edited by
    #1

    Hi all, i want to replace a exe default icon with any other icon. i have written this code to do this

    HANDLE hFile;
    DWORD dwFileSize, dwBytesRead;
    LPBYTE lpBuffer;
    HANDLE hResource;

    HRSRC hRes; // handle/ptr. to res. info. in hExe
    HANDLE hUpdateRes; // update resource handle
    char *lpResLock; // pointer to resource data
    HRSRC hResLoad; // handle to loaded resource
    BOOL result;
    HMODULE hSrcExe,hDestExe;
    int iLoop;

    hFile = CreateFile("E:\\icon.ico",
    GENERIC_READ,
    FILE_SHARE_READ,
    NULL,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    NULL);

    if (INVALID_HANDLE_VALUE != hFile)
    {
    dwFileSize = GetFileSize(hFile, NULL);
    lpBuffer = new BYTE[dwFileSize];
    int aa = ReadFile(hFile, lpBuffer, dwFileSize, &dwBytesRead, NULL);
    hResource = BeginUpdateResource("E:\\xyz.exe", FALSE);

    if (NULL != hResource)
    {
    	if (UpdateResource(hResource,
    			RT\_ICON,
    			MAKEINTRESOURCE(1),
    			MAKELANGID(LANG\_NEUTRAL, SUBLANG\_DEFAULT),
    			(LPVOID) lpBuffer,
    			dwFileSize) != FALSE)
    		{        
    			EndUpdateResource(hResource, FALSE);
    		}
    }
    

    }

    but its not updating the icon... I am not getting where is the problem. Can anybody help me in this... Thanks in advance

    L H 2 Replies Last reply
    0
    • L learningvisualc

      Hi all, i want to replace a exe default icon with any other icon. i have written this code to do this

      HANDLE hFile;
      DWORD dwFileSize, dwBytesRead;
      LPBYTE lpBuffer;
      HANDLE hResource;

      HRSRC hRes; // handle/ptr. to res. info. in hExe
      HANDLE hUpdateRes; // update resource handle
      char *lpResLock; // pointer to resource data
      HRSRC hResLoad; // handle to loaded resource
      BOOL result;
      HMODULE hSrcExe,hDestExe;
      int iLoop;

      hFile = CreateFile("E:\\icon.ico",
      GENERIC_READ,
      FILE_SHARE_READ,
      NULL,
      OPEN_EXISTING,
      FILE_ATTRIBUTE_NORMAL,
      NULL);

      if (INVALID_HANDLE_VALUE != hFile)
      {
      dwFileSize = GetFileSize(hFile, NULL);
      lpBuffer = new BYTE[dwFileSize];
      int aa = ReadFile(hFile, lpBuffer, dwFileSize, &dwBytesRead, NULL);
      hResource = BeginUpdateResource("E:\\xyz.exe", FALSE);

      if (NULL != hResource)
      {
      	if (UpdateResource(hResource,
      			RT\_ICON,
      			MAKEINTRESOURCE(1),
      			MAKELANGID(LANG\_NEUTRAL, SUBLANG\_DEFAULT),
      			(LPVOID) lpBuffer,
      			dwFileSize) != FALSE)
      		{        
      			EndUpdateResource(hResource, FALSE);
      		}
      }
      

      }

      but its not updating the icon... I am not getting where is the problem. Can anybody help me in this... Thanks in advance

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You do not check the return status from your commands, apart from not executing the UpdateResource() `or` EndUpdateResource() functions if an error occurs. You should run your code through the debugger to see if everything gets executed correctly, and if not, check any error codes by using GetLastError().

      txtspeak is the realm of 9 year old children, not developers. Christian Graus

      L 1 Reply Last reply
      0
      • L Lost User

        You do not check the return status from your commands, apart from not executing the UpdateResource() `or` EndUpdateResource() functions if an error occurs. You should run your code through the debugger to see if everything gets executed correctly, and if not, check any error codes by using GetLastError().

        txtspeak is the realm of 9 year old children, not developers. Christian Graus

        L Offline
        L Offline
        learningvisualc
        wrote on last edited by
        #3

        i have seen that everthing is executing fine, then also icon is not getting replaced.

        L 1 Reply Last reply
        0
        • L learningvisualc

          i have seen that everthing is executing fine, then also icon is not getting replaced.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          learningvisualc wrote:

          i have seen that everthing is executing fine, then also icon is not getting replaced.

          Sorry, but I cannot think of anything else to suggest, other than to check that you are using the correct resource id in the destination executable. If each function returns success status then it should work.

          txtspeak is the realm of 9 year old children, not developers. Christian Graus

          1 Reply Last reply
          0
          • L learningvisualc

            Hi all, i want to replace a exe default icon with any other icon. i have written this code to do this

            HANDLE hFile;
            DWORD dwFileSize, dwBytesRead;
            LPBYTE lpBuffer;
            HANDLE hResource;

            HRSRC hRes; // handle/ptr. to res. info. in hExe
            HANDLE hUpdateRes; // update resource handle
            char *lpResLock; // pointer to resource data
            HRSRC hResLoad; // handle to loaded resource
            BOOL result;
            HMODULE hSrcExe,hDestExe;
            int iLoop;

            hFile = CreateFile("E:\\icon.ico",
            GENERIC_READ,
            FILE_SHARE_READ,
            NULL,
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL,
            NULL);

            if (INVALID_HANDLE_VALUE != hFile)
            {
            dwFileSize = GetFileSize(hFile, NULL);
            lpBuffer = new BYTE[dwFileSize];
            int aa = ReadFile(hFile, lpBuffer, dwFileSize, &dwBytesRead, NULL);
            hResource = BeginUpdateResource("E:\\xyz.exe", FALSE);

            if (NULL != hResource)
            {
            	if (UpdateResource(hResource,
            			RT\_ICON,
            			MAKEINTRESOURCE(1),
            			MAKELANGID(LANG\_NEUTRAL, SUBLANG\_DEFAULT),
            			(LPVOID) lpBuffer,
            			dwFileSize) != FALSE)
            		{        
            			EndUpdateResource(hResource, FALSE);
            		}
            }
            

            }

            but its not updating the icon... I am not getting where is the problem. Can anybody help me in this... Thanks in advance

            H Offline
            H Offline
            HetzelGJ
            wrote on last edited by
            #5

            Try looking up the WM_SETICON message on the MSDN site, "An application sends the WM_SETICON message to associate a new large or small icon with a window. The system displays the large icon in the ALT+TAB dialog box, and the small icon in the window caption."

            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