DelFreak
asked on
Change icon of exe
I have a number of Delphi programs that I made. I would like to change their icons so that I have a standard icon for all my programs. The problem is, I don't have the source code for some of my programs. Can anyone post source code for a program that can change the icon of an executable. Thanks!
The freeware program reshacker makes this sort of thing easy
http://www.rpi.net.au/~ajohnson/resourcehacker/
http://www.rpi.net.au/~ajohnson/resourcehacker/
ASKER
It would be great if source code is posted. I would love to know how to do this. If anyone else could help, please do. Thanks!
ASKER
I found source code that changes the icon of an exe. unfortunately, it's in C. Can anyone of you convert it to Delphi for me? Please! Thanks!
can you post the source?
ASKER
Here's the source of IconWhack.h:
// My Constants
#define MAX_FILELEN 256
#define MAX_ICONSIZE 1600
#define WACK_SIG 0x4B434157L
#define NBITMAPS 8
#define NBUTTONS 4
#define BMPHEIGHT 64
#define BMPWIDTH 64
// Resource Constants
#define IDE1 1
#define IDE2 2
#define IDE3 3
#define IDE4 4
#define IDE5 5
#define IDE6 6
#define IDE7 7
#define IDE8 8
#define IDE9 9
#define IDE10 10
#define IDE11 11
#define IDE12 12
#define IDE13 13
//
#define CM_HELP 203
#define CM_EXIT 202
#define CM_WHACK 201
#define CM_HELPABOUT 206
#define CM_UNWHACK 205
//
#define IDC_EDIT1 101
#define IDC_EDIT2 102
#define IDC_ICONLB 104
#define IDC_BROWSEICO 106
#define IDC_BROWSEEXE 103
#define IDC_ICONEXE 105
#define IDC_DLG2_BROWSE 102
#define IDC_HELP 299
//
#define IDC_WACKFILE 101
//
typedef struct _NAMEINFO {
WORD rnOffset;
WORD rnLength;
WORD rnFlags;
WORD rnID;
WORD rnHandle;
WORD rnUsage;
} NAMEINFO;
typedef struct _TYPEINFO {
WORD rtTypeID;
WORD rtResourceCount;
DWORD rtReserved;
} TYPEINFO;
typedef struct _ICONDIR {
WORD idReserved;
WORD idType;
WORD idCount;
} ICONDIR;
typedef struct _ICONDIRENTRY {
BYTE bWidth;
BYTE bHeight;
BYTE bColorCount;
BYTE bReserved;
WORD wPlanes;
WORD wBitCount;
DWORD dwBytesinRes;
WORD wID;
} ICONDIRENTRY;
typedef struct _DISKICON {
BYTE bWidth;
BYTE bHeight;
BYTE bColorCount;
BYTE bRes1;
WORD bRes2;
WORD bRes3;
DWORD dwBytesinRes;
DWORD dwImageOffset;
} DISKICON;
typedef struct _IWICON {
DWORD startico;
DWORD starticodir;
DWORD dwBytesinRes;
BYTE bWidth;
BYTE bHeight;
BYTE bColorCount;
} IWICON;
typedef IWICON * PIWICON;
typedef IWICON NEAR * NPIWICON;
typedef IWICON FAR * LPIWICON;
//
// Function Prototypes
//
long FAR PASCAL _export WndProc(HWND,WORD,WPARAM,L PARAM);
BOOL FAR PASCAL _export DlgProc1(HWND,WORD,WPARAM, LPARAM);
BOOL FAR PASCAL _export DlgProc2(HWND,WORD,WPARAM, LPARAM);
BOOL FAR PASCAL _export DlgProcAbout(HWND,WORD,WPA RAM,LPARAM );
int MyCommand(HWND,WPARAM);
void CenterDialog(HWND);
WORD WhackExe(const char *,const char *,WORD);
WORD UnWhackExe(const char *);
WORD SeekIcon(HFILE,PIWICON,WOR D,BYTE,BYT E,BYTE);
int FileExists(const char *);
BOOL BrowseFile(HWND,WORD,char *);
void DrawBitmap(HDC,HBITMAP,WOR D,WORD);
//
Hers' the source of IWHelp.h:
//
// Help Constants
//
#define HLP_DLG1 400
#define HLP_DLG2 401
#define HLP_DONATIONS 402
//
Here's the source of IconWhack.c:
//
// EXE File Icon Whacker
// By: Mitch Howard - 10/95
//
#include <windows.h>
#include <commdlg.h>
#include <mmsystem.h>
#include <shellapi.h>
#include <stdlib.h>
#include <mem.h>
#include <dir.h>
#include "iconwack.h"
#include "iwhelp.h"
const char *appname = "IconWhack";
const char *HelpFileName = "ICONWACK.HLP";
const char *IniName = "ICONWACK.INI";
int SoundFlag;
HANDLE hInst;
HICON hicon;
HBITMAP hBmp[NBITMAPS];
HWND hwndBtn[NBUTTONS];
#pragma argsused
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
WORD tx,ty;
MSG msg;
WNDCLASS wc;
HWND hwnd;
hInst = hInstance; // Store Instance in Global variable
hicon = LoadIcon(hInstance,"ICONWA CK_ICON"); // Store Icon in Global var
hBmp[0] = LoadBitmap(hInstance,"WACK _UP");
hBmp[1] = LoadBitmap(hInstance,"WACK _DOWN");
hBmp[2] = LoadBitmap(hInstance,"UNWA CK_UP");
hBmp[3] = LoadBitmap(hInstance,"UNWA CK_DOWN");
hBmp[4] = LoadBitmap(hInstance,"HELP _UP");
hBmp[5] = LoadBitmap(hInstance,"HELP _DOWN");
hBmp[6] = LoadBitmap(hInstance,"EXIT _UP");
hBmp[7] = LoadBitmap(hInstance,"EXIT _DOWN");
SoundFlag = FALSE;
if (waveOutGetNumDevs() > 0)
SoundFlag = TRUE;
if (!hPrevInstance) {
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = hicon;
wc.hCursor = LoadCursor(NULL,IDC_ARROW) ;
wc.hbrBackground = GetStockObject(WHITE_BRUSH );
wc.lpszMenuName = "ICONWACK_MENU";
wc.lpszClassName = appname;
RegisterClass(&wc);
}
tx = GetSystemMetrics(SM_CXFRAM E)*2 + (BMPHEIGHT * NBUTTONS) + NBUTTONS;
ty = GetSystemMetrics(SM_CYFRAM E)*2 + GetSystemMetrics(SM_CYMENU );
ty += GetSystemMetrics(SM_CYCAPT ION) + BMPHEIGHT + 1;
hwnd = CreateWindow(appname,appna me, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
tx, ty, NULL, NULL, hInstance, NULL);
CenterDialog(hwnd);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg,NULL,0,0) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
long FAR PASCAL WndProc(HWND hwnd, WORD message, WPARAM wParam, LPARAM lParam)
{
WORD z;
LPMEASUREITEMSTRUCT lpMeasure;
LPDRAWITEMSTRUCT lpDraw;
switch (message) {
case WM_CREATE:
for (z = 0; z < NBUTTONS; z++) {
hwndBtn[z] = CreateWindow("button","",B S_OWNERDRA W | WS_CHILD | WS_VISIBLE | WS_BORDER,
z * BMPWIDTH + 2,1,BMPWIDTH,BMPHEIGHT,hwn d,z+1,hIns t,NULL);
}
return 0;
case WM_DESTROY:
WinHelp(hwnd,HelpFileName, HELP_QUIT, 0L);
for (z = 0; z < NBITMAPS; z++) {
if (hBmp[z])
DeleteObject(hBmp[z]);
}
PostQuitMessage(0);
return 0;
case WM_MEASUREITEM:
lpMeasure = (LPMEASUREITEMSTRUCT) lParam;
lpMeasure->CtlType = ODT_BUTTON;
for (z = 0; z < NBUTTONS; z++) {
if (wParam == hwndBtn[z]) {
lpMeasure->CtlID = z+1;
break;
}
}
lpMeasure->itemID = 0;
lpMeasure->itemWidth = BMPWIDTH;
lpMeasure->itemHeight = BMPHEIGHT;
lpMeasure->itemData = 0;
return 0;
case WM_DRAWITEM:
lpDraw = (DRAWITEMSTRUCT FAR*) lParam;
if ((lpDraw->itemAction == ODA_DRAWENTIRE) || (lpDraw->itemAction == ODA_SELECT)) {
for (z = 0; z < NBUTTONS; z++) {
if (lpDraw->CtlID == z+1) {
if (lpDraw->itemState & ODS_SELECTED)
DrawBitmap(lpDraw->hDC,hBm p[z+z+1],l pDraw->rcI tem.left,l pDraw->rcI tem.top);
else
DrawBitmap(lpDraw->hDC,hBm p[z+z],lpD raw->rcIte m.left,lpD raw->rcIte m.top);
}
}
}
return 0;
case WM_COMMAND:
if (LOWORD(lParam)) { // From a Control
switch (HIWORD(lParam)) {
case BN_CLICKED:
switch (wParam) {
case 1:
PostMessage(hwnd,WM_COMMAN D,CM_WHACK ,0L);
break;
case 2:
PostMessage(hwnd,WM_COMMAN D,CM_UNWHA CK,0L);
break;
case 3:
PostMessage(hwnd,WM_COMMAN D,CM_HELP, 0L);
break;
case 4:
PostMessage(hwnd,WM_COMMAN D,CM_EXIT, 0L);
break;
}
}
return 0;
}
else {
if (MyCommand(hwnd,wParam) == 0)
return 0;
}
break;
}
return DefWindowProc(hwnd,message ,wParam,lP aram);
}
int MyCommand(HWND hwnd,WPARAM wParam)
{
//
// Handle WM_COMMAND messages
// Returns TRUE if the message was not handled
//
DLGPROC dlgproc;
switch (wParam) {
case CM_WHACK:
dlgproc = MakeProcInstance(DlgProc1, hInst);
DialogBox(hInst,"ICONWACK_ DLG1",hwnd ,dlgproc);
FreeProcInstance(dlgproc);
break;
case CM_UNWHACK:
dlgproc = MakeProcInstance(DlgProc2, hInst);
DialogBox(hInst,"ICONWACK_ DLG2",hwnd ,dlgproc);
FreeProcInstance(dlgproc);
break;
case CM_HELPABOUT:
dlgproc = MakeProcInstance(DlgProcAb out, hInst);
DialogBox(hInst,"ICONWACK_ ABOUT",hwn d,dlgproc) ;
FreeProcInstance(dlgproc);
break;
case CM_HELP:
WinHelp(hwnd,HelpFileName, HELP_CONTE NTS,0L);
break;
case CM_EXIT:
SendMessage(hwnd,WM_CLOSE, 0,0L);
break;
default:
return TRUE;
}
return FALSE;
}
BOOL FAR PASCAL _export DlgProc1(HWND hDlg,WORD message,WPARAM wParam,LPARAM lParam)
{
char exename[MAX_FILELEN];
char iconame[MAX_FILELEN];
static char temp[MAX_FILELEN+20];
int oldmode, iconum;
HWND lbwh, icwh;
HICON hic, nicons;
WORD z, iw;
UINT inum;
HDC hdc;
HPEN oldpen;
LPMEASUREITEMSTRUCT lpMeasure;
LPDRAWITEMSTRUCT lpDraw;
RECT r;
switch (message) {
case WM_INITDIALOG:
CenterDialog(hDlg);
SendDlgItemMessage(hDlg,ID C_EDIT1,EM _LIMITTEXT ,MAX_FILEL EN,0L);
SendDlgItemMessage(hDlg,ID C_EDIT2,EM _LIMITTEXT ,MAX_FILEL EN,0L);
GetPrivateProfileString("W HACKDLG"," DEST","",e xename,MAX _FILELEN,I niName);
SetDlgItemText(hDlg,IDC_ED IT1,exenam e);
icwh = GetDlgItem(hDlg,IDC_ICONEX E);
if (FileExists(exename)) {
hic = ExtractIcon(hInst,exename, 0);
if (hic != NULL) {
SendDlgItemMessage(hDlg,ID C_ICONEXE, STM_SETICO N,(WPARAM) hic,0L);
InvalidateRect(icwh,NULL,T RUE);
UpdateWindow(icwh);
}
SetFocus(GetDlgItem(hDlg,I DC_EDIT2)) ;
}
GetPrivateProfileString("W HACKDLG"," SOURCE","" ,iconame,M AX_FILELEN ,IniName);
SetDlgItemText(hDlg,IDC_ED IT2,iconam e);
if (FileExists(iconame)) {
lbwh = GetDlgItem(hDlg,IDC_ICONLB );
nicons = ExtractIcon(hInst,iconame, -1);
if (nicons != NULL) {
SendMessage(lbwh,LB_RESETC ONTENT,0,0 L);
for (z = 0; z < nicons; z++)
SendMessage(lbwh,LB_ADDSTR ING,0,z);
SendMessage(lbwh,LB_SETCUR SEL,0,0);
}
SetFocus(GetDlgItem(hDlg,I DC_ICONLB) );
}
return TRUE;
case WM_MEASUREITEM:
lpMeasure = (LPMEASUREITEMSTRUCT) lParam;
lpMeasure->CtlType = ODT_LISTBOX;
lpMeasure->CtlID = IDC_ICONLB;
lpMeasure->itemID = 0;
lpMeasure->itemWidth = GetSystemMetrics(SM_CXICON ) + 2;
lpMeasure->itemHeight = GetSystemMetrics(SM_CYICON ) + 2;
lpMeasure->itemData = 0;
return TRUE;
case WM_DRAWITEM:
lpDraw = (DRAWITEMSTRUCT FAR*) lParam;
hdc = lpDraw->hDC;
r = lpDraw->rcItem;
inum = (UINT) lpDraw->itemData;
switch (lpDraw->itemAction) {
case ODA_DRAWENTIRE:
case ODA_SELECT:
GetDlgItemText(hDlg,IDC_ED IT2,iconam e,MAX_FILE LEN);
hic = ExtractIcon(hInst,iconame, inum);
if (hic != NULL) {
DrawIcon(hdc,r.left+2,r.to p+2,hic);
DestroyIcon(hic);
}
return TRUE;
case ODA_FOCUS:
oldmode = SetBkMode(hdc,TRANSPARENT) ;
if (lpDraw->itemState & ODS_FOCUS)
oldpen = SelectObject(hdc,GetStockO bject(BLAC K_PEN));
else
oldpen = SelectObject(hdc,GetStockO bject(WHIT E_PEN));
MoveTo(hdc,r.left,r.top);
iw = GetSystemMetrics(SM_CXICON );
LineTo(hdc,r.left+iw+3,r.t op);
LineTo(hdc,r.left+iw+3,r.b ottom+1);
LineTo(hdc,r.left,r.bottom +1);
LineTo(hdc,r.left,r.top);
SelectObject(hdc,oldpen);
SetBkMode(hdc,oldmode);
return TRUE;
}
return (FALSE);
case WM_COMMAND:
switch (wParam) {
case IDC_HELP:
WinHelp(hDlg,HelpFileName, HELP_CONTE XT,HLP_DLG 1);
return TRUE;
case IDC_BROWSEEXE:
if (BrowseFile(hDlg,0,exename )) {
SetDlgItemText(hDlg,IDC_ED IT1,exenam e);
icwh = GetDlgItem(hDlg,IDC_ICONEX E);
if (FileExists(exename)) {
hic = ExtractIcon(hInst,exename, 0);
if (hic == NULL)
MessageBox(hDlg,"No icons in this EXE file.","Error",MB_OK);
else {
SendDlgItemMessage(hDlg,ID C_ICONEXE, STM_SETICO N,(WPARAM) hic,0L);
InvalidateRect(icwh,NULL,T RUE);
UpdateWindow(icwh);
}
SetFocus(GetDlgItem(hDlg,I DC_EDIT2)) ;
}
else
SetFocus(GetDlgItem(hDlg,I DC_EDIT1)) ;
}
else
SetFocus(GetDlgItem(hDlg,I DC_EDIT1)) ;
// SendDlgItemMessage(hDlg, IDC_BROWSEEXE, BM_SETSTATE, FALSE, 0L);
return TRUE;
case IDC_BROWSEICO:
if (BrowseFile(hDlg,1,iconame )) {
lbwh = GetDlgItem(hDlg,IDC_ICONLB );
if (FileExists(iconame)) {
nicons = ExtractIcon(hInst,iconame, -1);
if (nicons == NULL)
MessageBox(hDlg,"No icons in this file.","Error",MB_OK);
else {
SetDlgItemText(hDlg,IDC_ED IT2,iconam e);
SendMessage(lbwh,LB_RESETC ONTENT,0,0 L);
for (z = 0; z < nicons; z++)
SendMessage(lbwh,LB_ADDSTR ING,0,z);
SendMessage(lbwh,LB_SETCUR SEL,0,0);
}
SetFocus(GetDlgItem(hDlg,I DC_ICONLB) );
}
else
SetFocus(GetDlgItem(hDlg,I DC_EDIT2)) ;
}
else
SetFocus(GetDlgItem(hDlg,I DC_EDIT2)) ;
return TRUE;
case IDC_EDIT1:
switch (HIWORD(lParam)) {
case EN_KILLFOCUS:
GetDlgItemText(hDlg,IDC_ED IT1,exenam e,MAX_FILE LEN);
if (lstrcmp(exename,temp)) {
icwh = GetDlgItem(hDlg,IDC_ICONEX E);
if (FileExists(exename)) {
hic = ExtractIcon(hInst,exename, 0);
if (hic == NULL)
MessageBox(hDlg,"No icons in this EXE file.","Error",MB_OK);
else {
SendDlgItemMessage(hDlg,ID C_ICONEXE, STM_SETICO N,(WPARAM) hic,0L);
InvalidateRect(icwh,NULL,T RUE);
UpdateWindow(icwh);
}
}
}
break;
case EN_SETFOCUS:
GetDlgItemText(hDlg,IDC_ED IT1,temp,M AX_FILELEN );
break;
}
return TRUE;
case IDC_EDIT2:
switch (HIWORD(lParam)) {
case EN_KILLFOCUS:
GetDlgItemText(hDlg,IDC_ED IT2,iconam e,MAX_FILE LEN);
if (lstrcmp(iconame,temp)) {
lbwh = GetDlgItem(hDlg,IDC_ICONLB );
if (FileExists(iconame)) {
nicons = ExtractIcon(hInst,iconame, -1);
if (nicons == NULL)
MessageBox(hDlg,"No icons in this file.","Error",MB_OK);
else {
SendMessage(lbwh,LB_RESETC ONTENT,0,0 L);
for (z = 0; z < nicons; z++)
SendMessage(lbwh,LB_ADDSTR ING,0,z);
SendMessage(lbwh,LB_SETCUR SEL,0,0);
}
}
else
SendMessage(lbwh,LB_RESETC ONTENT,0,0 L);
}
break;
case EN_SETFOCUS:
GetDlgItemText(hDlg,IDC_ED IT2,temp,M AX_FILELEN );
break;
}
return TRUE;
case IDOK:
GetDlgItemText(hDlg,IDC_ED IT1,exenam e,MAX_FILE LEN);
GetDlgItemText(hDlg,IDC_ED IT2,iconam e,MAX_FILE LEN);
if (FileExists(exename)) {
if (FileExists(iconame)) {
WritePrivateProfileString( "WHACKDLG" ,"DEST",ex ename,IniN ame);
WritePrivateProfileString( "WHACKDLG" ,"SOURCE", iconame,In iName);
WritePrivateProfileString( NULL,NULL, NULL,IniNa me); // Flush INI file
iconum = (int) SendDlgItemMessage(hDlg,ID C_ICONLB,L B_GETCURSE L,0,0L);
if (iconum >= 0) {
z = WhackExe(exename,iconame,i conum);
if (z > 0) {
LoadString(hInst,z,temp,60 );
MessageBox(hDlg,temp,"Msg" ,MB_OK);
}
else {
wsprintf(temp,"Icon in %s has been Wacked.",(LPSTR) exename);
MessageBox(hDlg,temp,"Succ essful Whack",MB_OK);
}
EndDialog(hDlg,0);
}
}
else {
MessageBox(hDlg,"You must specify an valid ICO/EXE/DLL file.","Error",MB_OK);
SetFocus(GetDlgItem(hDlg,I DC_EDIT2)) ;
}
}
else {
MessageBox(hDlg,"You must specify an existing .EXE file.","Error",MB_OK);
SetFocus(GetDlgItem(hDlg,I DC_EDIT1)) ;
}
return TRUE;
case IDCANCEL:
EndDialog(hDlg,0);
return TRUE;
}
break;
}
return FALSE;
}
#pragma argsused
BOOL FAR PASCAL _export DlgProc2(HWND hDlg,WORD message,WPARAM wParam,LPARAM lParam)
{
char wackname[MAX_FILELEN];
switch (message) {
case WM_INITDIALOG:
CenterDialog(hDlg);
SendDlgItemMessage(hDlg,ID C_WACKFILE ,EM_LIMITT EXT,MAX_FI LELEN,0L);
GetPrivateProfileString("U NWHACKDLG" ,"FILE","" ,wackname, MAX_FILELE N,IniName) ;
SetDlgItemText(hDlg,IDC_WA CKFILE,wac kname);
return TRUE;
case WM_COMMAND:
switch (wParam) {
case IDC_HELP:
WinHelp(hDlg,HelpFileName, HELP_CONTE XT,HLP_DLG 2);
return TRUE;
case IDC_DLG2_BROWSE:
if (BrowseFile(hDlg,2,wacknam e))
SetDlgItemText(hDlg,IDC_WA CKFILE,wac kname);
SetFocus(GetDlgItem(hDlg,I DC_WACKFIL E));
return TRUE;
case IDOK:
GetDlgItemText(hDlg,IDC_WA CKFILE,wac kname,MAX_ FILELEN);
if (FileExists(wackname)) {
WritePrivateProfileString( "UNWHACKDL G","FILE", wackname,I niName);
WritePrivateProfileString( NULL,NULL, NULL,IniNa me); // Flush INI file
if (UnWhackExe(wackname))
MessageBox(hDlg,"Cannot restore Icon in EXE","Error",MB_OK);
else
MessageBox(hDlg,"Original Icon restored.","Successful UnWhack",MB_OK);
EndDialog(hDlg,0);
}
else {
MessageBox(hDlg,"You must specify a valid .WCK file.","Error",MB_OK);
SetFocus(GetDlgItem(hDlg,I DC_WACKFIL E));
}
return TRUE;
case IDCANCEL:
EndDialog(hDlg,0);
return TRUE;
}
break;
}
return FALSE;
}
#pragma argsused
BOOL FAR PASCAL _export DlgProcAbout(HWND hDlg,WORD message,WPARAM wParam,LPARAM lParam)
{
switch (message) {
case WM_INITDIALOG:
CenterDialog(hDlg);
return TRUE;
case WM_COMMAND:
switch (wParam) {
case IDC_HELP:
SetFocus(GetDlgItem(hDlg,I DOK));
WinHelp(hDlg,HelpFileName, HELP_CONTE XT,HLP_DON ATIONS);
return TRUE;
case IDOK:
case IDCANCEL:
EndDialog(hDlg,0);
return TRUE;
}
break;
}
return FALSE;
}
void CenterDialog(HWND hwnd)
{
WORD ww, wh;
RECT rect, desktop;
GetWindowRect(GetDesktopWi ndow(),&de sktop);
GetWindowRect(hwnd,&rect);
ww = rect.right - rect.left;
wh = rect.bottom - rect.top;
MoveWindow(hwnd,(desktop.r ight-ww)/2 ,(desktop. bottom-wh) /2,ww,wh,T RUE);
return;
}
int FileExists(const char *fname)
{
//
// Checks to see if a file exists
// Returns TRUE if it is found
//
struct ffblk dirinfo;
if (findfirst(fname,&dirinfo, 0))
return FALSE;
return TRUE;
}
WORD SeekIcon(HFILE exefile,PIWICON piwicon,WORD iconum,BYTE cc,BYTE bw,BYTE bh)
{
//
// Seeks to a given Icon within an EXE or DLL
// Upon successful completion, the IWICON structure
// will be filled in with all relevant information.
//
WORD sig, head, rshift, z, offset, icmatch, TrueIconCount, tempcount;
LONG coffset, newpos, savepos;
TYPEINFO rti;
NAMEINFO nameinfo;
ICONDIR icondir;
ICONDIRENTRY icondirentry;
memset(piwicon,0,sizeof(IW ICON));
if (_llseek(exefile,0L,0) == -1)
return 3;
if (_lread(exefile,&sig,sizeo f(WORD)) != sizeof(WORD))
return 3;
// Check DOS EXE signature
if (sig != 0x5A4D)
return 4;
if (_llseek(exefile,0x18,0) == -1)
return 3;
if (_lread(exefile,&head,size of(WORD)) != sizeof(WORD))
return 3;
if (head < 0x40)
return 4; // Not an EXE that we can use
if (_llseek(exefile,0x3CL,0) == -1)
return 3;
if (_lread(exefile,&head,size of(WORD)) != sizeof(WORD))
return 3;
if (_llseek(exefile,(LONG) head,0) == -1)
return 3;
if (_lread(exefile,&sig,sizeo f(WORD)) != sizeof(WORD))
return 3;
// Check Win EXE signature
if (sig != 0x454E)
return 6;
if (_llseek(exefile,(LONG) head + 0x24L,0) == -1)
return 3;
if (_lread(exefile,&offset,si zeof(WORD) ) != sizeof(WORD))
return 3;
// Move to start of Resource Table
if (_llseek(exefile,(LONG) offset + (LONG) head,0) == -1)
return 3;
if (_lread(exefile,&z,sizeof( WORD)) != sizeof(WORD))
return 3;
rshift = 1;
if (z) {
while (z-- > 0)
rshift *= 2;
}
// Read each TYPEINFO structure in Resource Table
// looking for 0x0E (RT_GROUP_ICON) first and then 0x03 (RT_ICON)
icmatch = 0;
do {
if (_lread(exefile,&rti,sizeo f(TYPEINFO )) != sizeof(TYPEINFO))
return 3;
if ((rti.rtTypeID == 0) || (rti.rtReserved))
break;
coffset = _llseek(exefile,0L,1); // Save offset
if ((rti.rtTypeID & 0x7FFF) == 14) {
if (rti.rtResourceCount <= iconum)
return 5;
TrueIconCount = 0;
for (z = 0; z <= iconum; z++) {
if (_lread(exefile,&nameinfo, sizeof(NAM EINFO)) != sizeof(NAMEINFO))
return 3;
savepos = _llseek(exefile,0L,1); // Save current offset
newpos = (DWORD) rshift * (DWORD) nameinfo.rnOffset + 4L;
if (_llseek(exefile,newpos,0) == -1)
return 3;
if (_lread(exefile,&tempcount ,sizeof(WO RD)) != sizeof(WORD))
return 3;
if (z < iconum)
TrueIconCount += tempcount;
if (_llseek(exefile,savepos,0 ) == -1)
return 3;
}
piwicon->starticodir = newpos - 4L;
if (_llseek(exefile,piwicon-> starticodi r,0) == -1)
return 3;
if (_lread(exefile,&icondir,s izeof(ICON DIR)) != sizeof(ICONDIR))
return 3;
for (z = 1; z <= icondir.idCount; z++) {
if (_lread(exefile,&icondiren try,sizeof (ICONDIREN TRY)) != sizeof(ICONDIRENTRY))
return 3;
if ((icondirentry.bWidth == bw) && (icondirentry.bHeight == bh) && (icondirentry.bColorCount == cc)) {
icmatch = z;
break;
}
}
if (icondirentry.dwBytesinRes >= MAX_ICONSIZE)
return 10;
piwicon->bWidth = icondirentry.bWidth;
piwicon->bHeight = icondirentry.bHeight;
piwicon->bColorCount = icondirentry.bColorCount;
piwicon->dwBytesinRes = icondirentry.dwBytesinRes;
break;
}
if (_llseek(exefile,coffset + (LONG) rti.rtResourceCount * (LONG) sizeof(NAMEINFO),0) == -1)
return 3;
} while (piwicon->starticodir == 0L);
if (piwicon->starticodir == 0L)
return 7; // Cannot find Icons
//
// Look back thru Resource Table for the RT_ICON (0x03) Resource ID
//
if (_llseek(exefile,(LONG) offset + (LONG) head + (LONG) sizeof(WORD),0) == -1)
return 3;
do {
if (_lread(exefile,&rti,sizeo f(TYPEINFO )) != sizeof(TYPEINFO))
return 3;
if ((rti.rtTypeID == 0) || (rti.rtReserved))
break;
coffset = _llseek(exefile,0L,1); // Save offset
if ((rti.rtTypeID & 0x7FFF) == 3) {
if (rti.rtResourceCount <= TrueIconCount)
return 5;
if (_llseek(exefile,(LONG) TrueIconCount * (LONG) sizeof(NAMEINFO),1) == -1)
return 3;
if (_lread(exefile,&nameinfo, sizeof(NAM EINFO)) != sizeof(NAMEINFO))
return 3;
if ((icmatch > 1) && (rti.rtResourceCount > 1)) {
if (icmatch > rti.rtResourceCount)
return 11;
for (z = 2; z <= icmatch; z++) {
if (_lread(exefile,&nameinfo, sizeof(NAM EINFO)) != sizeof(NAMEINFO))
return 3;
}
}
piwicon->startico = (DWORD) rshift * (DWORD) nameinfo.rnOffset;
break;
}
if (_llseek(exefile,coffset + (LONG) rti.rtResourceCount * (LONG) sizeof(NAMEINFO),0) == -1)
return 3;
} while (piwicon->startico == 0L);
if (piwicon->startico == 0L)
return 7; // Cannot find Icons
return 0;
}
WORD WhackExe(const char *exename,const char *iconame,WORD iconum)
{
HFILE exefile, icofile, backupfile;
char backupname[MAX_FILELEN];
char tempname[MAX_FILELEN];
char iconbuf[MAX_ICONSIZE];
char savebuf[MAX_ICONSIZE];
BYTE iw, ih, ic;
WORD sig, err, z;
DWORD wacksig;
ICONDIR diskicondir;
DISKICON diskicon;
IWICON iwicon, tempiwicon;
HDC hdc;
if (SoundFlag)
// if (FileExists("WHACK.WAV"))
sndPlaySound("WHACK.WAV",S ND_ASYNC | SND_NODEFAULT);
z = lstrlen(exename);
if (z < 3)
return 4;
if (*(exename+z-1) != 'E')
return 4;
if (*(exename+z-2) != 'X')
return 4;
if (*(exename+z-3) != 'E')
return 4;
icofile = _lopen(iconame, READ);
if (icofile == -1)
return 1; // Cannot open ICO file
sig = 0;
if (_lread(icofile,&sig,sizeo f(WORD)) != sizeof(WORD))
sig = 0;
iw = (BYTE) GetSystemMetrics(SM_CXICON );
ih = (BYTE) GetSystemMetrics(SM_CYICON );
ic = 2; // Minimum Icon colors
hdc = GetDC(NULL);
if (GetDeviceCaps(hdc,SIZEPAL ETTE) > 16)
ic = 16; // Max icon colors
ReleaseDC(NULL, hdc);
if (sig == 0x5A4D) { // An EXE or DLL, so extract ICON data
err = SeekIcon(icofile,&tempiwic on,iconum, ic,iw,ih);
if (err) {
_lclose(icofile);
return err;
}
if (_llseek(icofile,tempiwico n.startico ,0) == -1) {
_lclose(icofile);
return 3;
}
if (_lread(icofile,&iconbuf[0 ],(WORD) tempiwicon.dwBytesinRes) != (WORD) tempiwicon.dwBytesinRes) {
_lclose(icofile);
return 3;
}
diskicondir.idReserved = 0;
diskicondir.idType = 1;
diskicondir.idCount = 1;
memset(&diskicon,0,sizeof( DISKICON)) ;
diskicon.bWidth = tempiwicon.bWidth;
diskicon.bHeight = tempiwicon.bHeight;
diskicon.bColorCount = tempiwicon.bColorCount;
diskicon.dwBytesinRes = tempiwicon.dwBytesinRes;
diskicon.dwImageOffset = sizeof(DISKICON) + sizeof(ICONDIR);
}
else {
_llseek(icofile,0L,0);
if (_lread(icofile,&diskicond ir,sizeof( ICONDIR)) != sizeof(ICONDIR)) {
_lclose(icofile);
return 3;
}
for (z = 1; z <= diskicondir.idCount; z++) {
if (_lread(icofile,&diskicon, sizeof(DIS KICON)) != sizeof(DISKICON)) {
_lclose(icofile);
return 3;
}
if ((diskicon.bColorCount == ic) && (diskicon.bWidth == iw) && (diskicon.bHeight == ih))
break;
}
if (_llseek(icofile,diskicon. dwImageOff set,0) == -1) {
_lclose(icofile);
return 3;
}
if (_lread(icofile,&iconbuf[0 ],(WORD) diskicon.dwBytesinRes) != (WORD) diskicon.dwBytesinRes) {
_lclose(icofile);
return 3;
}
}
_lclose(icofile);
// All Icon data is ready, so now write to EXE
exefile = _lopen(exename, READ_WRITE);
if (exefile == -1)
return 2;
err = SeekIcon(exefile,&iwicon,0 ,diskicon. bColorCoun t,diskicon .bWidth,di skicon.bHe ight);
if (err) {
_lclose(exefile);
return err;
}
// Check Icon compatibility (size, colors, height, width)
err = 0;
if ((diskicon.bWidth != iwicon.bWidth) || (diskicon.bHeight != iwicon.bHeight))
err = 13;
if (diskicon.bColorCount != iwicon.bColorCount)
err = 12;
if (diskicon.dwBytesinRes != iwicon.dwBytesinRes)
err = 11;
if (err == 0) {
if (_llseek(exefile,iwicon.st artico,0) != -1) {
// Save old data
if (_lread(exefile,&savebuf[0 ],(WORD) diskicon.dwBytesinRes) == (WORD) diskicon.dwBytesinRes) {
if (_llseek(exefile,iwicon.st artico,0) != -1) {
if (_lwrite(exefile,&iconbuf[ 0],(WORD) diskicon.dwBytesinRes) != (WORD) diskicon.dwBytesinRes)
err = 3;
}
else
err = 3;
}
else
err = 3;
}
else
err = 3;
}
_lclose(exefile);
if (err)
return err;
// Make backup file so that Icon change can be reversed
lstrcpy(backupname,exename );
memset(tempname,0,MAX_FILE LEN);
lstrcpy(tempname,exename);
z = lstrlen(backupname);
backupname[z-1] = 'K';
backupname[z-2] = 'C';
backupname[z-3] = 'W';
if (FileExists(backupname) == FALSE) {
backupfile = _lcreat(backupname, 0);
if (backupfile != -1) {
wacksig = WACK_SIG;
if (_lwrite(backupfile,&wacks ig,sizeof( DWORD)) == sizeof(DWORD)) {
if (_lwrite(backupfile,&tempn ame[0],MAX _FILELEN) == MAX_FILELEN) {
if (_lwrite(backupfile,&diski con.dwByte sinRes,siz eof(DWORD) ) == sizeof(DWORD)) {
if (_lwrite(backupfile,&iwico n.startico ,sizeof(DW ORD)) == sizeof(DWORD))
_lwrite(exefile,&savebuf[0 ],(WORD) diskicon.dwBytesinRes);
}
}
}
_lclose(backupfile);
}
}
return 0;
}
WORD UnWhackExe(const char *wackname)
{
HFILE wackfile, exefile;
DWORD wacksig, icosize, icostart;
char exename[MAX_FILELEN];
char iconbuf[MAX_ICONSIZE];
if (SoundFlag)
sndPlaySound("UNWHACK.WAV" ,SND_ASYNC | SND_NODEFAULT);
wackfile = _lopen(wackname,READ);
if (wackfile == -1)
return 2;
if (_lread(wackfile,&wacksig, sizeof(DWO RD)) != sizeof(DWORD)) {
_lclose(wackfile);
return 3;
}
if (wacksig != WACK_SIG) {
_lclose(wackfile);
return 4;
}
if (_lread(wackfile,exename,M AX_FILELEN ) != MAX_FILELEN) {
_lclose(wackfile);
return 3;
}
if (_lread(wackfile,&icosize, sizeof(DWO RD)) != sizeof(DWORD)) {
_lclose(wackfile);
return 3;
}
if (_lread(wackfile,&icostart ,sizeof(DW ORD)) != sizeof(DWORD)) {
_lclose(wackfile);
return 3;
}
if (_lread(wackfile,&iconbuf[ 0],(WORD) icosize) != (WORD) icosize) {
_lclose(wackfile);
return 3;
}
_lclose(wackfile);
if (FileExists(exename) == FALSE)
return 2;
exefile = _lopen(exename, READ_WRITE);
if (exefile == -1)
return 2;
if (_llseek(exefile,icostart, 0) == -1) {
_lclose(exefile);
return 3;
}
if (_lwrite(exefile,&iconbuf[ 0],(WORD) icosize) != (WORD) icosize) {
_lclose(exefile);
return 3;
}
_lclose(exefile);
return 0;
}
BOOL BrowseFile(HWND hwOwner,WORD btype,char *fnbuf)
{
BOOL retval;
WORD z;
char szFile[128];
char szFileTitle[128];
char szFilter[140];
OPENFILENAME ofn;
switch (btype) {
case 0:
lstrcpy(szFilter,"Program Files (*.exe)|*.exe||");
break;
case 1:
lstrcpy(szFilter,"All Files (exe,dll,ico)|*.exe;*.dll; *.ico|Prog ram Files (*.exe)|*.exe|DLL Files (*.dll)|*.dll|Icon Files (*.ico)|*.ico||");
break;
case 2:
lstrcpy(szFilter,"Whack Files (*.wck)|*.wck||");
break;
default:
return FALSE;
}
// Change all delimiters in Filter to nulls
for (z = 0; szFilter[z] != '\0'; z++) {
if (szFilter[z] == '|')
szFilter[z] = '\0';
}
memset(&ofn, 0, sizeof(OPENFILENAME)); // Init & clear Structure
szFile[0] = '\0';
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwOwner;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof(szFileTitle);
switch (btype) {
case 0:
ofn.lpstrTitle = "Browse Executables";
ofn.lpstrDefExt = "EXE";
break;
case 1:
ofn.lpstrTitle = "Browse Icons";
break;
case 2:
ofn.lpstrTitle = "Browse Whacked Files";
ofn.lpstrDefExt = "WCK";
break;
}
ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
retval = GetOpenFileName(&ofn);
if (retval)
lstrcpy(fnbuf,szFile);
return retval;
}
void DrawBitmap(HDC hdc,HBITMAP hBitmap,WORD xstart,WORD ystart)
{
BITMAP tempbm;
HBITMAP hOldBmp;
HDC hdcmem;
POINT ptsize, ptorg;
if (hBitmap == NULL)
return;
hdcmem = CreateCompatibleDC(hdc);
hOldBmp = SelectObject(hdcmem,hBitma p);
SetMapMode(hdcmem,GetMapMo de(hdc));
GetObject(hBitmap,sizeof(B ITMAP),(LP STR) &tempbm);
ptsize.x = tempbm.bmWidth;
ptsize.y = tempbm.bmHeight;
DPtoLP(hdc,&ptsize,1);
ptorg.x = 0;
ptorg.y = 0;
DPtoLP(hdcmem,&ptorg,1);
BitBlt(hdc,xstart,ystart,p tsize.x,pt size.y,hdc mem,ptorg. x,ptorg.y, SRCCOPY);
SelectObject(hdcmem,hOldBm p);
DeleteDC(hdcmem);
return;
}
After you have translated it, please post the source here. Thanks!
// My Constants
#define MAX_FILELEN 256
#define MAX_ICONSIZE 1600
#define WACK_SIG 0x4B434157L
#define NBITMAPS 8
#define NBUTTONS 4
#define BMPHEIGHT 64
#define BMPWIDTH 64
// Resource Constants
#define IDE1 1
#define IDE2 2
#define IDE3 3
#define IDE4 4
#define IDE5 5
#define IDE6 6
#define IDE7 7
#define IDE8 8
#define IDE9 9
#define IDE10 10
#define IDE11 11
#define IDE12 12
#define IDE13 13
//
#define CM_HELP 203
#define CM_EXIT 202
#define CM_WHACK 201
#define CM_HELPABOUT 206
#define CM_UNWHACK 205
//
#define IDC_EDIT1 101
#define IDC_EDIT2 102
#define IDC_ICONLB 104
#define IDC_BROWSEICO 106
#define IDC_BROWSEEXE 103
#define IDC_ICONEXE 105
#define IDC_DLG2_BROWSE 102
#define IDC_HELP 299
//
#define IDC_WACKFILE 101
//
typedef struct _NAMEINFO {
WORD rnOffset;
WORD rnLength;
WORD rnFlags;
WORD rnID;
WORD rnHandle;
WORD rnUsage;
} NAMEINFO;
typedef struct _TYPEINFO {
WORD rtTypeID;
WORD rtResourceCount;
DWORD rtReserved;
} TYPEINFO;
typedef struct _ICONDIR {
WORD idReserved;
WORD idType;
WORD idCount;
} ICONDIR;
typedef struct _ICONDIRENTRY {
BYTE bWidth;
BYTE bHeight;
BYTE bColorCount;
BYTE bReserved;
WORD wPlanes;
WORD wBitCount;
DWORD dwBytesinRes;
WORD wID;
} ICONDIRENTRY;
typedef struct _DISKICON {
BYTE bWidth;
BYTE bHeight;
BYTE bColorCount;
BYTE bRes1;
WORD bRes2;
WORD bRes3;
DWORD dwBytesinRes;
DWORD dwImageOffset;
} DISKICON;
typedef struct _IWICON {
DWORD startico;
DWORD starticodir;
DWORD dwBytesinRes;
BYTE bWidth;
BYTE bHeight;
BYTE bColorCount;
} IWICON;
typedef IWICON * PIWICON;
typedef IWICON NEAR * NPIWICON;
typedef IWICON FAR * LPIWICON;
//
// Function Prototypes
//
long FAR PASCAL _export WndProc(HWND,WORD,WPARAM,L
BOOL FAR PASCAL _export DlgProc1(HWND,WORD,WPARAM,
BOOL FAR PASCAL _export DlgProc2(HWND,WORD,WPARAM,
BOOL FAR PASCAL _export DlgProcAbout(HWND,WORD,WPA
int MyCommand(HWND,WPARAM);
void CenterDialog(HWND);
WORD WhackExe(const char *,const char *,WORD);
WORD UnWhackExe(const char *);
WORD SeekIcon(HFILE,PIWICON,WOR
int FileExists(const char *);
BOOL BrowseFile(HWND,WORD,char *);
void DrawBitmap(HDC,HBITMAP,WOR
//
Hers' the source of IWHelp.h:
//
// Help Constants
//
#define HLP_DLG1 400
#define HLP_DLG2 401
#define HLP_DONATIONS 402
//
Here's the source of IconWhack.c:
//
// EXE File Icon Whacker
// By: Mitch Howard - 10/95
//
#include <windows.h>
#include <commdlg.h>
#include <mmsystem.h>
#include <shellapi.h>
#include <stdlib.h>
#include <mem.h>
#include <dir.h>
#include "iconwack.h"
#include "iwhelp.h"
const char *appname = "IconWhack";
const char *HelpFileName = "ICONWACK.HLP";
const char *IniName = "ICONWACK.INI";
int SoundFlag;
HANDLE hInst;
HICON hicon;
HBITMAP hBmp[NBITMAPS];
HWND hwndBtn[NBUTTONS];
#pragma argsused
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
WORD tx,ty;
MSG msg;
WNDCLASS wc;
HWND hwnd;
hInst = hInstance; // Store Instance in Global variable
hicon = LoadIcon(hInstance,"ICONWA
hBmp[0] = LoadBitmap(hInstance,"WACK
hBmp[1] = LoadBitmap(hInstance,"WACK
hBmp[2] = LoadBitmap(hInstance,"UNWA
hBmp[3] = LoadBitmap(hInstance,"UNWA
hBmp[4] = LoadBitmap(hInstance,"HELP
hBmp[5] = LoadBitmap(hInstance,"HELP
hBmp[6] = LoadBitmap(hInstance,"EXIT
hBmp[7] = LoadBitmap(hInstance,"EXIT
SoundFlag = FALSE;
if (waveOutGetNumDevs() > 0)
SoundFlag = TRUE;
if (!hPrevInstance) {
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = hicon;
wc.hCursor = LoadCursor(NULL,IDC_ARROW)
wc.hbrBackground = GetStockObject(WHITE_BRUSH
wc.lpszMenuName = "ICONWACK_MENU";
wc.lpszClassName = appname;
RegisterClass(&wc);
}
tx = GetSystemMetrics(SM_CXFRAM
ty = GetSystemMetrics(SM_CYFRAM
ty += GetSystemMetrics(SM_CYCAPT
hwnd = CreateWindow(appname,appna
CW_USEDEFAULT, CW_USEDEFAULT,
tx, ty, NULL, NULL, hInstance, NULL);
CenterDialog(hwnd);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg,NULL,0,0)
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
long FAR PASCAL WndProc(HWND hwnd, WORD message, WPARAM wParam, LPARAM lParam)
{
WORD z;
LPMEASUREITEMSTRUCT lpMeasure;
LPDRAWITEMSTRUCT lpDraw;
switch (message) {
case WM_CREATE:
for (z = 0; z < NBUTTONS; z++) {
hwndBtn[z] = CreateWindow("button","",B
z * BMPWIDTH + 2,1,BMPWIDTH,BMPHEIGHT,hwn
}
return 0;
case WM_DESTROY:
WinHelp(hwnd,HelpFileName,
for (z = 0; z < NBITMAPS; z++) {
if (hBmp[z])
DeleteObject(hBmp[z]);
}
PostQuitMessage(0);
return 0;
case WM_MEASUREITEM:
lpMeasure = (LPMEASUREITEMSTRUCT) lParam;
lpMeasure->CtlType = ODT_BUTTON;
for (z = 0; z < NBUTTONS; z++) {
if (wParam == hwndBtn[z]) {
lpMeasure->CtlID = z+1;
break;
}
}
lpMeasure->itemID = 0;
lpMeasure->itemWidth = BMPWIDTH;
lpMeasure->itemHeight = BMPHEIGHT;
lpMeasure->itemData = 0;
return 0;
case WM_DRAWITEM:
lpDraw = (DRAWITEMSTRUCT FAR*) lParam;
if ((lpDraw->itemAction == ODA_DRAWENTIRE) || (lpDraw->itemAction == ODA_SELECT)) {
for (z = 0; z < NBUTTONS; z++) {
if (lpDraw->CtlID == z+1) {
if (lpDraw->itemState & ODS_SELECTED)
DrawBitmap(lpDraw->hDC,hBm
else
DrawBitmap(lpDraw->hDC,hBm
}
}
}
return 0;
case WM_COMMAND:
if (LOWORD(lParam)) { // From a Control
switch (HIWORD(lParam)) {
case BN_CLICKED:
switch (wParam) {
case 1:
PostMessage(hwnd,WM_COMMAN
break;
case 2:
PostMessage(hwnd,WM_COMMAN
break;
case 3:
PostMessage(hwnd,WM_COMMAN
break;
case 4:
PostMessage(hwnd,WM_COMMAN
break;
}
}
return 0;
}
else {
if (MyCommand(hwnd,wParam) == 0)
return 0;
}
break;
}
return DefWindowProc(hwnd,message
}
int MyCommand(HWND hwnd,WPARAM wParam)
{
//
// Handle WM_COMMAND messages
// Returns TRUE if the message was not handled
//
DLGPROC dlgproc;
switch (wParam) {
case CM_WHACK:
dlgproc = MakeProcInstance(DlgProc1,
DialogBox(hInst,"ICONWACK_
FreeProcInstance(dlgproc);
break;
case CM_UNWHACK:
dlgproc = MakeProcInstance(DlgProc2,
DialogBox(hInst,"ICONWACK_
FreeProcInstance(dlgproc);
break;
case CM_HELPABOUT:
dlgproc = MakeProcInstance(DlgProcAb
DialogBox(hInst,"ICONWACK_
FreeProcInstance(dlgproc);
break;
case CM_HELP:
WinHelp(hwnd,HelpFileName,
break;
case CM_EXIT:
SendMessage(hwnd,WM_CLOSE,
break;
default:
return TRUE;
}
return FALSE;
}
BOOL FAR PASCAL _export DlgProc1(HWND hDlg,WORD message,WPARAM wParam,LPARAM lParam)
{
char exename[MAX_FILELEN];
char iconame[MAX_FILELEN];
static char temp[MAX_FILELEN+20];
int oldmode, iconum;
HWND lbwh, icwh;
HICON hic, nicons;
WORD z, iw;
UINT inum;
HDC hdc;
HPEN oldpen;
LPMEASUREITEMSTRUCT lpMeasure;
LPDRAWITEMSTRUCT lpDraw;
RECT r;
switch (message) {
case WM_INITDIALOG:
CenterDialog(hDlg);
SendDlgItemMessage(hDlg,ID
SendDlgItemMessage(hDlg,ID
GetPrivateProfileString("W
SetDlgItemText(hDlg,IDC_ED
icwh = GetDlgItem(hDlg,IDC_ICONEX
if (FileExists(exename)) {
hic = ExtractIcon(hInst,exename,
if (hic != NULL) {
SendDlgItemMessage(hDlg,ID
InvalidateRect(icwh,NULL,T
UpdateWindow(icwh);
}
SetFocus(GetDlgItem(hDlg,I
}
GetPrivateProfileString("W
SetDlgItemText(hDlg,IDC_ED
if (FileExists(iconame)) {
lbwh = GetDlgItem(hDlg,IDC_ICONLB
nicons = ExtractIcon(hInst,iconame,
if (nicons != NULL) {
SendMessage(lbwh,LB_RESETC
for (z = 0; z < nicons; z++)
SendMessage(lbwh,LB_ADDSTR
SendMessage(lbwh,LB_SETCUR
}
SetFocus(GetDlgItem(hDlg,I
}
return TRUE;
case WM_MEASUREITEM:
lpMeasure = (LPMEASUREITEMSTRUCT) lParam;
lpMeasure->CtlType = ODT_LISTBOX;
lpMeasure->CtlID = IDC_ICONLB;
lpMeasure->itemID = 0;
lpMeasure->itemWidth = GetSystemMetrics(SM_CXICON
lpMeasure->itemHeight = GetSystemMetrics(SM_CYICON
lpMeasure->itemData = 0;
return TRUE;
case WM_DRAWITEM:
lpDraw = (DRAWITEMSTRUCT FAR*) lParam;
hdc = lpDraw->hDC;
r = lpDraw->rcItem;
inum = (UINT) lpDraw->itemData;
switch (lpDraw->itemAction) {
case ODA_DRAWENTIRE:
case ODA_SELECT:
GetDlgItemText(hDlg,IDC_ED
hic = ExtractIcon(hInst,iconame,
if (hic != NULL) {
DrawIcon(hdc,r.left+2,r.to
DestroyIcon(hic);
}
return TRUE;
case ODA_FOCUS:
oldmode = SetBkMode(hdc,TRANSPARENT)
if (lpDraw->itemState & ODS_FOCUS)
oldpen = SelectObject(hdc,GetStockO
else
oldpen = SelectObject(hdc,GetStockO
MoveTo(hdc,r.left,r.top);
iw = GetSystemMetrics(SM_CXICON
LineTo(hdc,r.left+iw+3,r.t
LineTo(hdc,r.left+iw+3,r.b
LineTo(hdc,r.left,r.bottom
LineTo(hdc,r.left,r.top);
SelectObject(hdc,oldpen);
SetBkMode(hdc,oldmode);
return TRUE;
}
return (FALSE);
case WM_COMMAND:
switch (wParam) {
case IDC_HELP:
WinHelp(hDlg,HelpFileName,
return TRUE;
case IDC_BROWSEEXE:
if (BrowseFile(hDlg,0,exename
SetDlgItemText(hDlg,IDC_ED
icwh = GetDlgItem(hDlg,IDC_ICONEX
if (FileExists(exename)) {
hic = ExtractIcon(hInst,exename,
if (hic == NULL)
MessageBox(hDlg,"No icons in this EXE file.","Error",MB_OK);
else {
SendDlgItemMessage(hDlg,ID
InvalidateRect(icwh,NULL,T
UpdateWindow(icwh);
}
SetFocus(GetDlgItem(hDlg,I
}
else
SetFocus(GetDlgItem(hDlg,I
}
else
SetFocus(GetDlgItem(hDlg,I
// SendDlgItemMessage(hDlg, IDC_BROWSEEXE, BM_SETSTATE, FALSE, 0L);
return TRUE;
case IDC_BROWSEICO:
if (BrowseFile(hDlg,1,iconame
lbwh = GetDlgItem(hDlg,IDC_ICONLB
if (FileExists(iconame)) {
nicons = ExtractIcon(hInst,iconame,
if (nicons == NULL)
MessageBox(hDlg,"No icons in this file.","Error",MB_OK);
else {
SetDlgItemText(hDlg,IDC_ED
SendMessage(lbwh,LB_RESETC
for (z = 0; z < nicons; z++)
SendMessage(lbwh,LB_ADDSTR
SendMessage(lbwh,LB_SETCUR
}
SetFocus(GetDlgItem(hDlg,I
}
else
SetFocus(GetDlgItem(hDlg,I
}
else
SetFocus(GetDlgItem(hDlg,I
return TRUE;
case IDC_EDIT1:
switch (HIWORD(lParam)) {
case EN_KILLFOCUS:
GetDlgItemText(hDlg,IDC_ED
if (lstrcmp(exename,temp)) {
icwh = GetDlgItem(hDlg,IDC_ICONEX
if (FileExists(exename)) {
hic = ExtractIcon(hInst,exename,
if (hic == NULL)
MessageBox(hDlg,"No icons in this EXE file.","Error",MB_OK);
else {
SendDlgItemMessage(hDlg,ID
InvalidateRect(icwh,NULL,T
UpdateWindow(icwh);
}
}
}
break;
case EN_SETFOCUS:
GetDlgItemText(hDlg,IDC_ED
break;
}
return TRUE;
case IDC_EDIT2:
switch (HIWORD(lParam)) {
case EN_KILLFOCUS:
GetDlgItemText(hDlg,IDC_ED
if (lstrcmp(iconame,temp)) {
lbwh = GetDlgItem(hDlg,IDC_ICONLB
if (FileExists(iconame)) {
nicons = ExtractIcon(hInst,iconame,
if (nicons == NULL)
MessageBox(hDlg,"No icons in this file.","Error",MB_OK);
else {
SendMessage(lbwh,LB_RESETC
for (z = 0; z < nicons; z++)
SendMessage(lbwh,LB_ADDSTR
SendMessage(lbwh,LB_SETCUR
}
}
else
SendMessage(lbwh,LB_RESETC
}
break;
case EN_SETFOCUS:
GetDlgItemText(hDlg,IDC_ED
break;
}
return TRUE;
case IDOK:
GetDlgItemText(hDlg,IDC_ED
GetDlgItemText(hDlg,IDC_ED
if (FileExists(exename)) {
if (FileExists(iconame)) {
WritePrivateProfileString(
WritePrivateProfileString(
WritePrivateProfileString(
iconum = (int) SendDlgItemMessage(hDlg,ID
if (iconum >= 0) {
z = WhackExe(exename,iconame,i
if (z > 0) {
LoadString(hInst,z,temp,60
MessageBox(hDlg,temp,"Msg"
}
else {
wsprintf(temp,"Icon in %s has been Wacked.",(LPSTR) exename);
MessageBox(hDlg,temp,"Succ
}
EndDialog(hDlg,0);
}
}
else {
MessageBox(hDlg,"You must specify an valid ICO/EXE/DLL file.","Error",MB_OK);
SetFocus(GetDlgItem(hDlg,I
}
}
else {
MessageBox(hDlg,"You must specify an existing .EXE file.","Error",MB_OK);
SetFocus(GetDlgItem(hDlg,I
}
return TRUE;
case IDCANCEL:
EndDialog(hDlg,0);
return TRUE;
}
break;
}
return FALSE;
}
#pragma argsused
BOOL FAR PASCAL _export DlgProc2(HWND hDlg,WORD message,WPARAM wParam,LPARAM lParam)
{
char wackname[MAX_FILELEN];
switch (message) {
case WM_INITDIALOG:
CenterDialog(hDlg);
SendDlgItemMessage(hDlg,ID
GetPrivateProfileString("U
SetDlgItemText(hDlg,IDC_WA
return TRUE;
case WM_COMMAND:
switch (wParam) {
case IDC_HELP:
WinHelp(hDlg,HelpFileName,
return TRUE;
case IDC_DLG2_BROWSE:
if (BrowseFile(hDlg,2,wacknam
SetDlgItemText(hDlg,IDC_WA
SetFocus(GetDlgItem(hDlg,I
return TRUE;
case IDOK:
GetDlgItemText(hDlg,IDC_WA
if (FileExists(wackname)) {
WritePrivateProfileString(
WritePrivateProfileString(
if (UnWhackExe(wackname))
MessageBox(hDlg,"Cannot restore Icon in EXE","Error",MB_OK);
else
MessageBox(hDlg,"Original Icon restored.","Successful UnWhack",MB_OK);
EndDialog(hDlg,0);
}
else {
MessageBox(hDlg,"You must specify a valid .WCK file.","Error",MB_OK);
SetFocus(GetDlgItem(hDlg,I
}
return TRUE;
case IDCANCEL:
EndDialog(hDlg,0);
return TRUE;
}
break;
}
return FALSE;
}
#pragma argsused
BOOL FAR PASCAL _export DlgProcAbout(HWND hDlg,WORD message,WPARAM wParam,LPARAM lParam)
{
switch (message) {
case WM_INITDIALOG:
CenterDialog(hDlg);
return TRUE;
case WM_COMMAND:
switch (wParam) {
case IDC_HELP:
SetFocus(GetDlgItem(hDlg,I
WinHelp(hDlg,HelpFileName,
return TRUE;
case IDOK:
case IDCANCEL:
EndDialog(hDlg,0);
return TRUE;
}
break;
}
return FALSE;
}
void CenterDialog(HWND hwnd)
{
WORD ww, wh;
RECT rect, desktop;
GetWindowRect(GetDesktopWi
GetWindowRect(hwnd,&rect);
ww = rect.right - rect.left;
wh = rect.bottom - rect.top;
MoveWindow(hwnd,(desktop.r
return;
}
int FileExists(const char *fname)
{
//
// Checks to see if a file exists
// Returns TRUE if it is found
//
struct ffblk dirinfo;
if (findfirst(fname,&dirinfo,
return FALSE;
return TRUE;
}
WORD SeekIcon(HFILE exefile,PIWICON piwicon,WORD iconum,BYTE cc,BYTE bw,BYTE bh)
{
//
// Seeks to a given Icon within an EXE or DLL
// Upon successful completion, the IWICON structure
// will be filled in with all relevant information.
//
WORD sig, head, rshift, z, offset, icmatch, TrueIconCount, tempcount;
LONG coffset, newpos, savepos;
TYPEINFO rti;
NAMEINFO nameinfo;
ICONDIR icondir;
ICONDIRENTRY icondirentry;
memset(piwicon,0,sizeof(IW
if (_llseek(exefile,0L,0) == -1)
return 3;
if (_lread(exefile,&sig,sizeo
return 3;
// Check DOS EXE signature
if (sig != 0x5A4D)
return 4;
if (_llseek(exefile,0x18,0) == -1)
return 3;
if (_lread(exefile,&head,size
return 3;
if (head < 0x40)
return 4; // Not an EXE that we can use
if (_llseek(exefile,0x3CL,0) == -1)
return 3;
if (_lread(exefile,&head,size
return 3;
if (_llseek(exefile,(LONG) head,0) == -1)
return 3;
if (_lread(exefile,&sig,sizeo
return 3;
// Check Win EXE signature
if (sig != 0x454E)
return 6;
if (_llseek(exefile,(LONG) head + 0x24L,0) == -1)
return 3;
if (_lread(exefile,&offset,si
return 3;
// Move to start of Resource Table
if (_llseek(exefile,(LONG) offset + (LONG) head,0) == -1)
return 3;
if (_lread(exefile,&z,sizeof(
return 3;
rshift = 1;
if (z) {
while (z-- > 0)
rshift *= 2;
}
// Read each TYPEINFO structure in Resource Table
// looking for 0x0E (RT_GROUP_ICON) first and then 0x03 (RT_ICON)
icmatch = 0;
do {
if (_lread(exefile,&rti,sizeo
return 3;
if ((rti.rtTypeID == 0) || (rti.rtReserved))
break;
coffset = _llseek(exefile,0L,1); // Save offset
if ((rti.rtTypeID & 0x7FFF) == 14) {
if (rti.rtResourceCount <= iconum)
return 5;
TrueIconCount = 0;
for (z = 0; z <= iconum; z++) {
if (_lread(exefile,&nameinfo,
return 3;
savepos = _llseek(exefile,0L,1); // Save current offset
newpos = (DWORD) rshift * (DWORD) nameinfo.rnOffset + 4L;
if (_llseek(exefile,newpos,0)
return 3;
if (_lread(exefile,&tempcount
return 3;
if (z < iconum)
TrueIconCount += tempcount;
if (_llseek(exefile,savepos,0
return 3;
}
piwicon->starticodir = newpos - 4L;
if (_llseek(exefile,piwicon->
return 3;
if (_lread(exefile,&icondir,s
return 3;
for (z = 1; z <= icondir.idCount; z++) {
if (_lread(exefile,&icondiren
return 3;
if ((icondirentry.bWidth == bw) && (icondirentry.bHeight == bh) && (icondirentry.bColorCount == cc)) {
icmatch = z;
break;
}
}
if (icondirentry.dwBytesinRes
return 10;
piwicon->bWidth = icondirentry.bWidth;
piwicon->bHeight = icondirentry.bHeight;
piwicon->bColorCount = icondirentry.bColorCount;
piwicon->dwBytesinRes = icondirentry.dwBytesinRes;
break;
}
if (_llseek(exefile,coffset + (LONG) rti.rtResourceCount * (LONG) sizeof(NAMEINFO),0) == -1)
return 3;
} while (piwicon->starticodir == 0L);
if (piwicon->starticodir == 0L)
return 7; // Cannot find Icons
//
// Look back thru Resource Table for the RT_ICON (0x03) Resource ID
//
if (_llseek(exefile,(LONG) offset + (LONG) head + (LONG) sizeof(WORD),0) == -1)
return 3;
do {
if (_lread(exefile,&rti,sizeo
return 3;
if ((rti.rtTypeID == 0) || (rti.rtReserved))
break;
coffset = _llseek(exefile,0L,1); // Save offset
if ((rti.rtTypeID & 0x7FFF) == 3) {
if (rti.rtResourceCount <= TrueIconCount)
return 5;
if (_llseek(exefile,(LONG) TrueIconCount * (LONG) sizeof(NAMEINFO),1) == -1)
return 3;
if (_lread(exefile,&nameinfo,
return 3;
if ((icmatch > 1) && (rti.rtResourceCount > 1)) {
if (icmatch > rti.rtResourceCount)
return 11;
for (z = 2; z <= icmatch; z++) {
if (_lread(exefile,&nameinfo,
return 3;
}
}
piwicon->startico = (DWORD) rshift * (DWORD) nameinfo.rnOffset;
break;
}
if (_llseek(exefile,coffset + (LONG) rti.rtResourceCount * (LONG) sizeof(NAMEINFO),0) == -1)
return 3;
} while (piwicon->startico == 0L);
if (piwicon->startico == 0L)
return 7; // Cannot find Icons
return 0;
}
WORD WhackExe(const char *exename,const char *iconame,WORD iconum)
{
HFILE exefile, icofile, backupfile;
char backupname[MAX_FILELEN];
char tempname[MAX_FILELEN];
char iconbuf[MAX_ICONSIZE];
char savebuf[MAX_ICONSIZE];
BYTE iw, ih, ic;
WORD sig, err, z;
DWORD wacksig;
ICONDIR diskicondir;
DISKICON diskicon;
IWICON iwicon, tempiwicon;
HDC hdc;
if (SoundFlag)
// if (FileExists("WHACK.WAV"))
sndPlaySound("WHACK.WAV",S
z = lstrlen(exename);
if (z < 3)
return 4;
if (*(exename+z-1) != 'E')
return 4;
if (*(exename+z-2) != 'X')
return 4;
if (*(exename+z-3) != 'E')
return 4;
icofile = _lopen(iconame, READ);
if (icofile == -1)
return 1; // Cannot open ICO file
sig = 0;
if (_lread(icofile,&sig,sizeo
sig = 0;
iw = (BYTE) GetSystemMetrics(SM_CXICON
ih = (BYTE) GetSystemMetrics(SM_CYICON
ic = 2; // Minimum Icon colors
hdc = GetDC(NULL);
if (GetDeviceCaps(hdc,SIZEPAL
ic = 16; // Max icon colors
ReleaseDC(NULL, hdc);
if (sig == 0x5A4D) { // An EXE or DLL, so extract ICON data
err = SeekIcon(icofile,&tempiwic
if (err) {
_lclose(icofile);
return err;
}
if (_llseek(icofile,tempiwico
_lclose(icofile);
return 3;
}
if (_lread(icofile,&iconbuf[0
_lclose(icofile);
return 3;
}
diskicondir.idReserved = 0;
diskicondir.idType = 1;
diskicondir.idCount = 1;
memset(&diskicon,0,sizeof(
diskicon.bWidth = tempiwicon.bWidth;
diskicon.bHeight = tempiwicon.bHeight;
diskicon.bColorCount = tempiwicon.bColorCount;
diskicon.dwBytesinRes = tempiwicon.dwBytesinRes;
diskicon.dwImageOffset = sizeof(DISKICON) + sizeof(ICONDIR);
}
else {
_llseek(icofile,0L,0);
if (_lread(icofile,&diskicond
_lclose(icofile);
return 3;
}
for (z = 1; z <= diskicondir.idCount; z++) {
if (_lread(icofile,&diskicon,
_lclose(icofile);
return 3;
}
if ((diskicon.bColorCount == ic) && (diskicon.bWidth == iw) && (diskicon.bHeight == ih))
break;
}
if (_llseek(icofile,diskicon.
_lclose(icofile);
return 3;
}
if (_lread(icofile,&iconbuf[0
_lclose(icofile);
return 3;
}
}
_lclose(icofile);
// All Icon data is ready, so now write to EXE
exefile = _lopen(exename, READ_WRITE);
if (exefile == -1)
return 2;
err = SeekIcon(exefile,&iwicon,0
if (err) {
_lclose(exefile);
return err;
}
// Check Icon compatibility (size, colors, height, width)
err = 0;
if ((diskicon.bWidth != iwicon.bWidth) || (diskicon.bHeight != iwicon.bHeight))
err = 13;
if (diskicon.bColorCount != iwicon.bColorCount)
err = 12;
if (diskicon.dwBytesinRes != iwicon.dwBytesinRes)
err = 11;
if (err == 0) {
if (_llseek(exefile,iwicon.st
// Save old data
if (_lread(exefile,&savebuf[0
if (_llseek(exefile,iwicon.st
if (_lwrite(exefile,&iconbuf[
err = 3;
}
else
err = 3;
}
else
err = 3;
}
else
err = 3;
}
_lclose(exefile);
if (err)
return err;
// Make backup file so that Icon change can be reversed
lstrcpy(backupname,exename
memset(tempname,0,MAX_FILE
lstrcpy(tempname,exename);
z = lstrlen(backupname);
backupname[z-1] = 'K';
backupname[z-2] = 'C';
backupname[z-3] = 'W';
if (FileExists(backupname) == FALSE) {
backupfile = _lcreat(backupname, 0);
if (backupfile != -1) {
wacksig = WACK_SIG;
if (_lwrite(backupfile,&wacks
if (_lwrite(backupfile,&tempn
if (_lwrite(backupfile,&diski
if (_lwrite(backupfile,&iwico
_lwrite(exefile,&savebuf[0
}
}
}
_lclose(backupfile);
}
}
return 0;
}
WORD UnWhackExe(const char *wackname)
{
HFILE wackfile, exefile;
DWORD wacksig, icosize, icostart;
char exename[MAX_FILELEN];
char iconbuf[MAX_ICONSIZE];
if (SoundFlag)
sndPlaySound("UNWHACK.WAV"
wackfile = _lopen(wackname,READ);
if (wackfile == -1)
return 2;
if (_lread(wackfile,&wacksig,
_lclose(wackfile);
return 3;
}
if (wacksig != WACK_SIG) {
_lclose(wackfile);
return 4;
}
if (_lread(wackfile,exename,M
_lclose(wackfile);
return 3;
}
if (_lread(wackfile,&icosize,
_lclose(wackfile);
return 3;
}
if (_lread(wackfile,&icostart
_lclose(wackfile);
return 3;
}
if (_lread(wackfile,&iconbuf[
_lclose(wackfile);
return 3;
}
_lclose(wackfile);
if (FileExists(exename) == FALSE)
return 2;
exefile = _lopen(exename, READ_WRITE);
if (exefile == -1)
return 2;
if (_llseek(exefile,icostart,
_lclose(exefile);
return 3;
}
if (_lwrite(exefile,&iconbuf[
_lclose(exefile);
return 3;
}
_lclose(exefile);
return 0;
}
BOOL BrowseFile(HWND hwOwner,WORD btype,char *fnbuf)
{
BOOL retval;
WORD z;
char szFile[128];
char szFileTitle[128];
char szFilter[140];
OPENFILENAME ofn;
switch (btype) {
case 0:
lstrcpy(szFilter,"Program Files (*.exe)|*.exe||");
break;
case 1:
lstrcpy(szFilter,"All Files (exe,dll,ico)|*.exe;*.dll;
break;
case 2:
lstrcpy(szFilter,"Whack Files (*.wck)|*.wck||");
break;
default:
return FALSE;
}
// Change all delimiters in Filter to nulls
for (z = 0; szFilter[z] != '\0'; z++) {
if (szFilter[z] == '|')
szFilter[z] = '\0';
}
memset(&ofn, 0, sizeof(OPENFILENAME)); // Init & clear Structure
szFile[0] = '\0';
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwOwner;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof(szFileTitle);
switch (btype) {
case 0:
ofn.lpstrTitle = "Browse Executables";
ofn.lpstrDefExt = "EXE";
break;
case 1:
ofn.lpstrTitle = "Browse Icons";
break;
case 2:
ofn.lpstrTitle = "Browse Whacked Files";
ofn.lpstrDefExt = "WCK";
break;
}
ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
retval = GetOpenFileName(&ofn);
if (retval)
lstrcpy(fnbuf,szFile);
return retval;
}
void DrawBitmap(HDC hdc,HBITMAP hBitmap,WORD xstart,WORD ystart)
{
BITMAP tempbm;
HBITMAP hOldBmp;
HDC hdcmem;
POINT ptsize, ptorg;
if (hBitmap == NULL)
return;
hdcmem = CreateCompatibleDC(hdc);
hOldBmp = SelectObject(hdcmem,hBitma
SetMapMode(hdcmem,GetMapMo
GetObject(hBitmap,sizeof(B
ptsize.x = tempbm.bmWidth;
ptsize.y = tempbm.bmHeight;
DPtoLP(hdc,&ptsize,1);
ptorg.x = 0;
ptorg.y = 0;
DPtoLP(hdcmem,&ptorg,1);
BitBlt(hdc,xstart,ystart,p
SelectObject(hdcmem,hOldBm
DeleteDC(hdcmem);
return;
}
After you have translated it, please post the source here. Thanks!
ASKER
Slavak, are you going to convert it?
I have not time just now. But I think the prefer way to update resources is use UpdateResource API function.
I did it sometime, but cannot find a code. For custom resources there is no problem, but grouped resources (such as icons) needs some trick. I'm not remember it just now :(.
Regards
I did it sometime, but cannot find a code. For custom resources there is no problem, but grouped resources (such as icons) needs some trick. I'm not remember it just now :(.
Regards
hi
to download jedi-VCL component,it have a example for you want(have all sourcecode with delphi),this example name peViewer.
jedi-vcl component:
URL ftp://delphi-jedi.org/Code_Library/Release_1_11/JCL.zip
to download jedi-VCL component,it have a example for you want(have all sourcecode with delphi),this example name peViewer.
jedi-vcl component:
URL ftp://delphi-jedi.org/Code_Library/Release_1_11/JCL.zip
Well, any resource editor should allow you to change it (if you are lucky enough to have MSVC then this is all you need).
Just open the resources of the application and change the ICON resource called MAINICON.
Cheers,
Raymond.
Just open the resources of the application and change the ICON resource called MAINICON.
Cheers,
Raymond.
ASKER
Does anyone else have any suggestions? I need code or maybe you can just convert the C code above. Thanks!
You don't need any source code! Just download a free resource editor (most should allow editing resources in EXEs) - http://www.google.com should find you a bunch in few seconds :-)
Cheers,
Raymond.
Cheers,
Raymond.
ASKER
Yes but I would like to learn how to do such a thing in Delphi. If you have code that does this or if you can translate the code above then I would really appreciate it. Thanks!
There is a demo in Delphi called ResExplorer. It does not save changes but it would be a good place to start if you were interested in learning about this stuff...
Cheers,
Raymond.
Cheers,
Raymond.
Hi Delfreak :-)
Ok Ok here is a VERY simple-minded program that can change the icon of another delphi exe. It just changes it to a solid green block... but you can easily alter this code to allow you to replace the icon with another icon... this code seems to work fine... but I wrote it in about 15 mins so it's bound to have some silly bug somewhere so you better look it over carefully :-)
First go get ExeMod.pas at my web site http://delphi.does.it
Put ExeMod.pas into the same dir as your project and add ExeMod to your uses clause... then add 2 buttons to your form and double click them to add event handlers...now add an opendialog ... finally just replace the entire code of the project with this code... I hope it formats correctly
Oh... I added a routine in button 2 that changes the Icon of your exe while it is running..... just click it and the icon will change to a green block.... button1 changes the icon of another exe :-)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExeMod;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button2Click(Sender : TObject);
Var
SearchStr: String;
x: Integer;
begin
ReadExe;
SearchStr := chr(192)+chr(192)+chr(0)+c hr(128)+ch r(128)+chr (128)+chr( 0)+chr(0)+ chr(0)+chr (255)+chr( 0)
+chr(0)+chr(255)+chr(0)+ch r(0)+chr(0 )+chr(255) +chr(255)+ chr(0)+chr (255)+chr( 0)
+chr(0)+chr(0)+chr(255)+ch r(0)+chr(2 55)+chr(0) +chr(255)+ chr(255)+c hr(0)+chr( 0);
SearchStr := SearchStr +chr(255)+chr(255)+chr(255 )+chr(0);
if pos(SearchStr,Exe) = 0 then exit;
for x := (pos(SearchStr,Exe)+35) to (pos(SearchStr,Exe))+546 do
begin
Exe[x] := chr(170);
end;
AlterExe;
end;
procedure TForm1.Button1Click(Sender : TObject);
Var
MyString,SearchStr: String;
x: Integer;
begin
OpenDialog1.Execute;
MyString := File2String(OpenDialog1.Fi leName);
SearchStr := chr(192)+chr(192)+chr(0)+c hr(128)+ch r(128)+chr (128)+chr( 0)+chr(0)+ chr(0)+chr (255)+chr( 0)
+chr(0)+chr(255)+chr(0)+ch r(0)+chr(0 )+chr(255) +chr(255)+ chr(0)+chr (255)+chr( 0)
+chr(0)+chr(0)+chr(255)+ch r(0)+chr(2 55)+chr(0) +chr(255)+ chr(255)+c hr(0)+chr( 0);
SearchStr := SearchStr +chr(255)+chr(255)+chr(255 )+chr(0);
if pos(SearchStr,MyString) > 0 then
begin
for x := (pos(SearchStr,MyString)+3 5) to (pos(SearchStr,MyString))+ 546 do
begin
MyString[x] := chr(170);
end;
String2File(MyString,OpenD ialog1.Fil eName);
showmessage('ICON found and changed');
end
else showmessage('ICON not found in file');
end;
end.
Ok Ok here is a VERY simple-minded program that can change the icon of another delphi exe. It just changes it to a solid green block... but you can easily alter this code to allow you to replace the icon with another icon... this code seems to work fine... but I wrote it in about 15 mins so it's bound to have some silly bug somewhere so you better look it over carefully :-)
First go get ExeMod.pas at my web site http://delphi.does.it
Put ExeMod.pas into the same dir as your project and add ExeMod to your uses clause... then add 2 buttons to your form and double click them to add event handlers...now add an opendialog ... finally just replace the entire code of the project with this code... I hope it formats correctly
Oh... I added a routine in button 2 that changes the Icon of your exe while it is running..... just click it and the icon will change to a green block.... button1 changes the icon of another exe :-)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExeMod;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button2Click(Sender
Var
SearchStr: String;
x: Integer;
begin
ReadExe;
SearchStr := chr(192)+chr(192)+chr(0)+c
+chr(0)+chr(255)+chr(0)+ch
+chr(0)+chr(0)+chr(255)+ch
SearchStr := SearchStr +chr(255)+chr(255)+chr(255
if pos(SearchStr,Exe) = 0 then exit;
for x := (pos(SearchStr,Exe)+35) to (pos(SearchStr,Exe))+546 do
begin
Exe[x] := chr(170);
end;
AlterExe;
end;
procedure TForm1.Button1Click(Sender
Var
MyString,SearchStr: String;
x: Integer;
begin
OpenDialog1.Execute;
MyString := File2String(OpenDialog1.Fi
SearchStr := chr(192)+chr(192)+chr(0)+c
+chr(0)+chr(255)+chr(0)+ch
+chr(0)+chr(0)+chr(255)+ch
SearchStr := SearchStr +chr(255)+chr(255)+chr(255
if pos(SearchStr,MyString) > 0 then
begin
for x := (pos(SearchStr,MyString)+3
begin
MyString[x] := chr(170);
end;
String2File(MyString,OpenD
showmessage('ICON found and changed');
end
else showmessage('ICON not found in file');
end;
end.
Oh... there is 128 more bytes that follow the block I changed above... they are also part of the icon data... I just changed enough data to make a nice green blob :-) but to change the icon with another one you would need to add those as well.... I wrote a funny program just now that alters the exe's icon randomly every time it runs... it should make people curious... it would be easy to grab an icon from another exe at random and swap for that each time too... or make the icon count the number of times the exe has been run.. and display it in a colorful hex number... 00 to FF :-)
Gwena,
You are thinking evil thoughts - I can tell. This would be the basis of a pretty funny trojan - well, until the Feds caught up with you of course!
Cheers,
Raymond.
You are thinking evil thoughts - I can tell. This would be the basis of a pretty funny trojan - well, until the Feds caught up with you of course!
Cheers,
Raymond.
Hi rwilson :-)
There's not an ounce of mischief in me! I just like to write strange and mostly useless code...that's all :-)
There's not an ounce of mischief in me! I just like to write strange and mostly useless code...that's all :-)
This code lets you select a new .ico file by clicking button1 .. then you click button 2 to choose a delphi exe to insert the .ico into.. This is far from perfect but it works (at least it seems to) and it's something for you to fill out with some more code and experiment with... I wish I had more time so I could write some better code to do this... I tried this a couple of times on delphi exe's ... no idea what will happen with other exe files.... better back up any file before you attempt to operate on it with this code :-)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExeMod;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
IconStr: String;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender : TObject);
begin
OpenDialog1.Execute;
If Pos('.ico',OpenDialog1.Fil eName) > 0 then IconStr := File2String(OpenDialog1.Fi leName);
delete(IconStr,1,126);
end;
procedure TForm1.Button2Click(Sender : TObject);
Var
MyString,SearchStr: String;
x: Integer;
begin
OpenDialog1.Execute;
MyString := File2String(OpenDialog1.Fi leName);
SearchStr := chr(192)+chr(192)+chr(0)+c hr(128)+ch r(128)+chr (128)+chr( 0)+chr(0)+ chr(0)+chr (255)+chr( 0)
+chr(0)+chr(255)+chr(0)+ch r(0)+chr(0 )+chr(255) +chr(255)+ chr(0)+chr (255)+chr( 0)
+chr(0)+chr(0)+chr(255)+ch r(0)+chr(2 55)+chr(0) +chr(255)+ chr(255)+c hr(0)+chr( 0);
SearchStr := SearchStr +chr(255)+chr(255)+chr(255 )+chr(0);
if pos(SearchStr,MyString) > 0 then
begin
for x := 1 to 640 do
begin
MyString[(pos(SearchStr,My String)+34 )+x] := IconStr[x];
end;
String2File(MyString,OpenD ialog1.Fil eName);
showmessage('ICON found and changed');
end
else showmessage('ICON not found in file');
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExeMod;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
IconStr: String;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender
begin
OpenDialog1.Execute;
If Pos('.ico',OpenDialog1.Fil
delete(IconStr,1,126);
end;
procedure TForm1.Button2Click(Sender
Var
MyString,SearchStr: String;
x: Integer;
begin
OpenDialog1.Execute;
MyString := File2String(OpenDialog1.Fi
SearchStr := chr(192)+chr(192)+chr(0)+c
+chr(0)+chr(255)+chr(0)+ch
+chr(0)+chr(0)+chr(255)+ch
SearchStr := SearchStr +chr(255)+chr(255)+chr(255
if pos(SearchStr,MyString) > 0 then
begin
for x := 1 to 640 do
begin
MyString[(pos(SearchStr,My
end;
String2File(MyString,OpenD
showmessage('ICON found and changed');
end
else showmessage('ICON not found in file');
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
bugroger,
Yes, I downloaded IconHack.zip. It didn't do much for me. I'll try your code.
Gwena, your code works fine. But as you said, it isn't 100% efficient. Let me try bugroger's code first. Thanks!
Everyone else, thank you for your help.
Yes, I downloaded IconHack.zip. It didn't do much for me. I'll try your code.
Gwena, your code works fine. But as you said, it isn't 100% efficient. Let me try bugroger's code first. Thanks!
Everyone else, thank you for your help.
Hi delFreak :-)
Yup..my code works but..well... it still needs work
If I just had the time I think it could be tightened up to work pretty well... If anyone else wants to work on my code and make it better then just give them the points if it ends up being suitable for your tasks :-)
good luck...
Yup..my code works but..well... it still needs work
If I just had the time I think it could be tightened up to work pretty well... If anyone else wants to work on my code and make it better then just give them the points if it ends up being suitable for your tasks :-)
good luck...
ASKER
burgroger, sorry it took so long. Been really busy. Thanks for your code. Worked well!
Gwena, thanks too!
Gwena, thanks too!
You may want to try the following component:
http://www.torry.net/vcl/graphics/icons/mbexeicon.zip
TExeIcon is a small component for Delphi . With TExeIcon you can modify the main icon of a EXE file. The component was designed to add this capability to AutoRun Multimedia Creator, a free program to create AutoRuns. TExeIcon features:
Modify icon of Win32 Exe Files
Compatible with all Programming Languages
The source is not included and it's for D4...
I know one expert here has such a program on his website but I can't find it anymore... and the search engine on E-E SUCKS so badly...
This is a question already asked many times...
The answer is here... SO if you wait a bit someone may give you the answer....
john.