1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
unit iconchanger; {shaped by shapeless} interface uses windows; type PICONDIRENTRYCOMMON = ^ICONDIRENTRYCOMMON; ICONDIRENTRYCOMMON = packed record bWidth : Byte; // Width, in pixels, of the image bHeight : Byte; // Height, in pixels, of the image bColorCount : Byte; // Number of colors in image (0 if >=8bpp) bReserved : Byte; // Reserved ( must be 0) wPlanes : Word; // Color Planes wBitCount : Word; // Bits per pixel dwBytesInRes : DWord; // How many bytes in this resource? end; PICONDIRENTRY = ^ICONDIRENTRY; ICONDIRENTRY = packed record common : ICONDIRENTRYCOMMON; dwImageOffset : DWord; // Where in the file is this image? end; PICONDIR = ^ICONDIR; ICONDIR = packed record idReserved : Word; // Reserved (must be 0) idType : Word; // Resource Type (1 for icons) idCount : Word; // How many images? idEntries : ICONDIRENTRY; // An entry for each image (idCount of 'em) end; PGRPICONDIRENTRY = ^GRPICONDIRENTRY; GRPICONDIRENTRY = packed record common : ICONDIRENTRYCOMMON; nID : Word; // the ID end; PGRPICONDIR = ^GRPICONDIR; GRPICONDIR = packed record idReserved : Word; // Reserved (must be 0) idType : Word; // Resource type (1 for icons) idCount : Word; // How many images? idEntries : GRPICONDIRENTRY; // The entries for each image end; function UpdateApplicationIcon(srcicon : PChar; destexe : PChar) : Boolean; implementation function UpdateApplicationIcon(srcicon : PChar; destexe : PChar) : Boolean; var hFile : Integer; id : ICONDIR; pid : PICONDIR; pgid : PGRPICONDIR; uRead : DWord; nSize : DWord; pvFile : PByte; hInst : LongInt; begin result := False; hFile := CreateFile(srcicon, GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if hFile > 0 then begin ReadFile(hFile, id, sizeof(id), uRead, nil); SetFilePointer(hFile, 0, nil, FILE_BEGIN); GetMem(pid, sizeof(ICONDIR) + sizeof(ICONDIRENTRY)); GetMem(pgid, sizeof(GRPICONDIR) + sizeof(GRPICONDIRENTRY)); ReadFile(hFile, pid^, sizeof(ICONDIR) + sizeof(ICONDIRENTRY), uRead, nil); move(pid^, pgid^, sizeof(GRPICONDIR)); pgid^.idEntries.common := pid^.idEntries.common; pgid^.idEntries.nID := 1; nSize := pid^.idEntries.common.dwBytesInRes; GetMem(pvFile, nSize); SetFilePointer(hFile, pid^.idEntries.dwImageOffset, nil, FILE_BEGIN); ReadFile(hFile, pvFile^, nSize, uRead, nil); CloseHandle(hFile); hInst:=BeginUpdateResource(destexe, False); if hInst > 0 then begin UpdateResource(hInst, RT_ICON, MAKEINTRESOURCE(1), LANG_NEUTRAL, pvFile, nSize); EndUpdateResource(hInst, False); result := True; end; FreeMem(pvFile); FreeMem(pgid); FreeMem(pid); end; end; end. |
Moduł ten umożliwia zmianę ikony pliku exe, działa na wszystkich prawie execach 😉 krzaczy się tylko na specjalnie modyfikowanych plikach etc. Ikonke zmieniamy funkcją UpdateApplicationIcon, pierwszy parametr to sciezka do ikony, a drugi do pliku .exe Mam nadzieje, że komuś się to przyda.
Zaznaczam ze kod nie jest mojego autorstwa.
Autor: Filuu