Comment passer une icone en "raw binary data"

youpiyoyo Messages postés 539 Date d'inscription vendredi 6 juin 2003 Statut Membre Dernière intervention 14 juillet 2010 - 24 juil. 2004 à 13:07
robinfinity Messages postés 1 Date d'inscription mercredi 29 septembre 2004 Statut Membre Dernière intervention 29 septembre 2004 - 29 sept. 2004 à 15:11
je cherche a mettre une icone dans une resource le probleme c ke j'ouvre l'ico comme ca

HICON Ico=ExtractIcon(MainhInstance,szFile,0);

ou szFile est ouvert par GetOpenFileName

bref dans mon

result = UpdateResource(hUpdateRes, // update resource handle
RT_ICON, // change dialog box resource
"ico", // dialog box name
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language
Ico, // ptr to resource info
SizeofResource(hExe, hRes)); // size of resource info.

dans msdn il est spécifié ke LPVOID lpData, "Note that this is the raw binary data stored in the executable file, not the data provided by LoadIcon, LoadString, or other resource-specific load functions. All data containing strings or text must be in Unicode format; lpData must not point to ANSI data.

quelk'1 aurait une suggestion???

youpi :)

6 réponses

ShareVB Messages postés 2676 Date d'inscription vendredi 28 juin 2002 Statut Membre Dernière intervention 13 janvier 2016 26
24 juil. 2004 à 15:17
salut

moi je ferais plutôt :

HMODULE hMod = LoadLibrary(szFile);
HRSRC hres = FindResource(hMod,MAKEINTRESOURCE(0),RT_ICON);
HGLOBAL hGlob = LoadResource(hMod,hres);
LPVOID lpRes = LockResource(hGlob);

//le reste de ton code
result = UpdateResource(hUpdateRes, // update resource handle
RT_ICON, // change dialog box resource
"ico", // dialog box name
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language
lpRes, // ptr to resource info
SizeofResource(hMod, hres)); // size of resource info.
FreeLibrary(hMod);

voilà

ShareVB
0
youpiyoyo Messages postés 539 Date d'inscription vendredi 6 juin 2003 Statut Membre Dernière intervention 14 juillet 2010
24 juil. 2004 à 15:22
ouai mais j'ouvre une icone genre x.ico

j'avais testé mais il me met l'application ou la dll n'est pas une image windows valid

findressource c pour unikement une dll ou un exe je crois

je suis entrain de voir avec un fopen en binaire voir si ca marche

youpi :)
0
ShareVB Messages postés 2676 Date d'inscription vendredi 28 juin 2002 Statut Membre Dernière intervention 13 janvier 2016 26
24 juil. 2004 à 15:32
salut

dans ce cas, regarde à "Icons in Win32" sur MSDN : cela montre le format des icones en ressource et .ico...

ShareVB
0
youpiyoyo Messages postés 539 Date d'inscription vendredi 6 juin 2003 Statut Membre Dernière intervention 14 juillet 2010
24 juil. 2004 à 15:37
ok je vais regarder mais sans prétention car j'ai deja bien fouiller
youpi :)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
youpiyoyo Messages postés 539 Date d'inscription vendredi 6 juin 2003 Statut Membre Dernière intervention 14 juillet 2010
24 juil. 2004 à 19:32
bon j'y suis toujours pas arriver j'ai fas ca

char* ico;
FILE* file=fopen(szFile,"rb");
FILE* filedest=fopen("dest.ico","w");
fpos_t pos;
if(fseek(file, 0,SEEK_END)!=0)MessageBox(0,"fseek erreur",0,0);
else
{
if( fgetpos( file, &pos ) == 0 )
{

ico=(char*) malloc((size_t)pos);
fseek(file, 0,SEEK_SET);
fread(ico, sizeof( char ), (int)pos, file );
//fwrite(ico,sizeof( char ), (int)pos,filedest);
}
}
fclose(file);
fclose(filedest);

ico devrait donc contenir en binaire les datas de l'ico,

mais kan je passe a

result = UpdateResource(hUpdateRes,
RT_ICON,
szTitre,
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
ico,
sizeof(ico));

ca me met une merde dans les resource.. help!!
youpi :)
0
robinfinity Messages postés 1 Date d'inscription mercredi 29 septembre 2004 Statut Membre Dernière intervention 29 septembre 2004
29 sept. 2004 à 15:11
Hi!
Sorry for writing in English, but I not good at all in French, even if I can understand a little bit of it...

The above code is almost okay to pass binary data from an icon to resource, but the problem is that you don't need to pass all the data from an ICO to the resource.

I have an icon file which has only one image, size 16x16, 256 colors, and I realized that the "good" data begins at the 22th byte in the ico file, so my code looks like this:

HANDLE hUpd=BeginUpdateResource(_T("_.exe"),FALSE);
UpdateResource((HMODULE)hUpd, RT_ICON,MAKEINTRESOURCE(1), 0x409, (LPBYTE)(ico+22), pos-22);
EndUpdateResource(hUpd, FALSE);

This will not work for other icons than size 16x16, 256 colors, or icon files containing multiple formats.

To find the correct code, I did a very "ugly" thing: made a loop from x=1 to pos (the size of the icon file) and took (pos-x) bytes from (ico+x) and copied them to the resource.
UpdateResource((HMODULE)hUpd, RT_ICON,MAKEINTRESOURCE(1), 0x409, (LPBYTE)(ico+x), pos-x);
Than created a sepparate exe file (opened the modified exe binary, and created a new binary file to copy its contents) for each iteration (x.exe) and than verified which one has a good icon :))

Thank you very much for idea!
0
Rejoignez-nous