Forum > Windows

Trying to do a resource update for icons and I'm nearly there ...

<< < (3/4) > >>

Martin_fr:

--- Quote from: Handoko on May 01, 2021, 07:23:21 pm ---
--- Quote from: lainz on May 01, 2021, 06:36:22 pm ---Changing the icon of an executable is not a crime.

--- End quote ---

I am not a student of criminology but I what know is if someone change the icon of my program without my permission, I won't happy.

--- End quote ---

We don't know what executable. For all we know it may be public domain, but without source, or he hasn't got the toolchain to build it himself.

Spoonhorse:
Hi.

(1) I think I know how to do this now, I have found my fundamental error. I need to take the icon file, split it into two parts and inject them into two different places.

(2) Changing the Application.Icon only changes the thing in the top left hand corner of your form. It doesn't change how it displays on the taskbar.

(3) If I wanted to do this for illegal purposes I could do it with Resource Hacker which I have downloaded. I want to give my users the capacity to do this. This is the only reason why anyone would want to do this in code.

(4) Guys, calm down. What crime could I commit and actually get away with through changing the icon? All the copyright information would still be there. In fact, I'm trying to do the exact opposite if anything — I've written a free program so customizable that the last step is to give it a new name and logo and publisher name and then even sell it for commercial purposes if you can find a buyer. Or give it away free, like decent people. I'm trying to give people every facility to do that. But because of point (2), in order for my program to do that for them I have to know how to do this. So far as I can see the only sensible way is to copy the .exe file of my program under a different name and do this. I have thought of one dumb way that increase the size of my setup.exe by orders of magnitude, one fairly sensible way which puts my users to mild inconvenience, one almost-sensible way which I have no idea how to start to implement, and one totally successful but incredibly lazy way which is also illegal, so I'm going with this one.

PascalDragon:

--- Quote from: Handoko on May 01, 2021, 07:23:21 pm ---
--- Quote from: lainz on May 01, 2021, 06:36:22 pm ---Changing the icon of an executable is not a crime.

--- End quote ---

I am not a student of criminology but I what know is if someone change the icon of my program without my permission, I won't happy.

--- End quote ---

I've used similar approaches in the past to change the boot icon of Windows XP (which required to modify a resource in the ntoskrnl.exe).

And even if I'd change the icon of your program on my computer what would you care if I wouldn't distribute it? Also I wouldn't even have to write my own software, cause I could just use one existing resource hacker software to do that.

lainz:

--- Quote from: PascalDragon on May 02, 2021, 02:20:41 pm ---
--- Quote from: Handoko on May 01, 2021, 07:23:21 pm ---
--- Quote from: lainz on May 01, 2021, 06:36:22 pm ---Changing the icon of an executable is not a crime.

--- End quote ---

I am not a student of criminology but I what know is if someone change the icon of my program without my permission, I won't happy.

--- End quote ---

I've used similar approaches in the past to change the boot icon of Windows XP (which required to modify a resource in the ntoskrnl.exe).

And even if I'd change the icon of your program on my computer what would you care if I wouldn't distribute it? Also I wouldn't even have to write my own software, cause I could just use one existing resource hacker software to do that.

--- End quote ---

Everyone did that in that times =) Customizing Windows XP. Even there was a time when you can add Windows Vista style to Windows XP changing the msstyles and explorer icons, all "hacking" system files exe or dll.

Spoonhorse:
OK people! The following is working code, don't do bad crimes with it! You'll need to put Windows in your uses statement.

Some notes on what effects it has on the application and Windows, because some of this is subtle.

(1) Although the application icon (in the top left corner of your main form) can be set to be completely different from the main icon for the program, it seems like it's overwritten to be in line with the main icon once you do the update. 99% of the time this would be exactly what you want. If it isn't what you want you'll have to take it from here.

(2) File Explorer caches this stuff so hard that you won't see any change in how the icon's displayed there unless you restart Explorer. This is fine for my purposes, if it's a problem for you then again you'll have to solve it yourself, sorry.

(3) This is NOT an answer to that frequently-asked question, "how do I change the toolbar icon of my Pascal-based application while it's running?" Because you can't do a resource update on an executable that's being executed, whether your own or another. What you could do, if you really must, is have your program save all its data and then shut down after starting a program which waits for it to shut down, changes its icon, and then starts it back up, at which point it reloads its data. This would work, but it would take time of course, you couldn't use it for something you'd want to change frequently like to indicate the status of the program.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var   vResHandle: THandle;      MyIcon: TMemoryStream;      i,j: integer;      s: string;      ImageCount: Word;      ImageSize: DWord;      ab, m: TMemoryStream; const HeaderSize = 6;      IcoEntrySize = 16;      ResEntrySize = 14; begin // Short explanation. An icon file consists of (a) a six-byte header which// includes among other things information about how many icons are in// the file; (b) sixteen bytes of metadata for each icon; (c) the icons. // But that's how icons are stored as files. As executable resources,// Windows considers that (a) and (b) are one resource but (c) is a different// resource, indeed one resource for each image, so we have to split the icon// file up and do several resource updates. // It also requires only fourteen bytes of metadata per entry: instead of the// last parameter being a double word referring to the position of the image// in memory, it's a single word conferring an ID. // Initialize stuffMyIcon := TMemoryStream.Create;ab := TMemoryStream.Create;m := TMemoryStream.Create; // Get the iconMyIcon.LoadFromFile('icon.ico'); // Get the handle for the resource update..vResHandle := BeginUpdateResource('test.exe', False); // We skip forward in the memory stream to where Windows keeps the image count and read it.MyIcon.Seek(4,soFromBeginning);ImageCount:=MyIcon.ReadWord; // Go back to the beginning ...MyIcon.Seek(0,soFromBeginning); // We read the directory information into ab, modifying its format as we do so. for j:=1 to HeaderSize do ab.WriteByte(MyIcon.ReadByte);    for i:=1 to ImageCount do        begin        for j:=1 to IcoEntrySize - 4 do ab.WriteByte(MyIcon.ReadByte);        MyIcon.ReadDWord;  // To skip over it.        ab.WriteWord(i);        end; // Update the icon directory with ab, which is now in the correct format. UpdateResource(vResHandle                      , RT_GROUP_ICON                      , PChar('MAINICON')                      , LANG_NEUTRAL                      , ab.Memory                      , ab.Size); // Now the size of each icon is contained as a double word in the directory// entries for each item, so we use that to cut the remainder of the memory// stream into chunks and update them one at a time. for i := 1 to ImageCount do    begin    m := TMemoryStream.Create;    ab.Seek(HeaderSize+(i-1)*ResEntrySize+8,soFromBeginning);    ImageSize:=ab.ReadDWord;    for j:=1 to ImageSize do m.WriteByte(MyIcon.ReadByte);    UpdateResource(vResHandle                  , RT_ICON                  , MAKEINTRESOURCE(i)                  , LANG_NEUTRAL                  , m.Memory                  , m.Size);    m.Free;    end; EndUpDateResource(vResHandle,False);MyIcon.Free;ab.Free;end;

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version