Passer de HICON en HBITMAP, pour menu

youpiyoyo Messages postés 539 Date d'inscription vendredi 6 juin 2003 Statut Membre Dernière intervention 14 juillet 2010 - 25 juin 2004 à 12:47
youpiyoyo Messages postés 539 Date d'inscription vendredi 6 juin 2003 Statut Membre Dernière intervention 14 juillet 2010 - 29 juin 2004 à 19:44
j'aurai besoin de passer un HICON en HBITMAP, pour pouvoir afficher une icone dans un menu j'ai testé avec copyimage sans succes.....

voici le bout de code

j'ai d'abord testé ca avec un cast sans succes
HBITMAP h_Bit = (HBITMAP) LoadImage
(
(HINSTANCE)hInstance, // handle of the instance that contains the image
(LPCTSTR)MAKEINTRESOURCE(IDI_ICO_MAIN), // name or identifier of image
(UINT)IMAGE_ICON, // type of image
(int)GetSystemMetrics(SM_CXMENUCHECK), // desired width
(int)GetSystemMetrics(SM_CYMENUCHECK), // desired height
(UINT)LR_SHARED // load flags
);
h_bit n'est po NULL mais fonctionnent po pour un SetMenuItemBitmaps(hMenuPopup,ID_POPUP_ABOUT,MF_BYCOMMAND,h_Bit,h_Bit);

donc...
ensuite
j'ai testé ca

HBITMAP h_Bit = (HBITMAP) CopyImage(LoadImage
(
(HINSTANCE)hInstance, // handle of the instance that contains the image
(LPCTSTR)MAKEINTRESOURCE(IDI_ICO_MAIN), // name or identifier of image
(UINT)IMAGE_ICON, // type of image
(int)GetSystemMetrics(SM_CXMENUCHECK), // desired width
(int)GetSystemMetrics(SM_CYMENUCHECK), // desired height
(UINT)LR_SHARED // load flags
),IMAGE_BITMAP,(int)13,(int)13,0);
veut pas convertir un IMAGE_ICON en IMAGE_BITMAP, avec getlasterror, il me renvoi 6....

please HELP me!!!! %-6

5 réponses

ShareVB Messages postés 2676 Date d'inscription vendredi 28 juin 2002 Statut Membre Dernière intervention 13 janvier 2016 26
25 juin 2004 à 19:10
salut

tu peux utiliser GetIconInfo :

HICON icon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICO_MAIN));
ICONINFO iconinfo={0};
BOOL ret = GetIconInfo(icon,&iconinfo);
HBITMAP iconbitmap = iconinfo.hbmColor;
SetMenuItemBitmaps(hMenuPopup,ID_POPUP_ABOUT,MF_BYCOMMAND,iconbitmap ,iconbitmap);

au cas ou le resultat ne serait pas satisfaisant, il est aussi simple de convertir ton icone en bitmap et de la mettre en ressource directement...

voilà

ShareVB
0
youpiyoyo Messages postés 539 Date d'inscription vendredi 6 juin 2003 Statut Membre Dernière intervention 14 juillet 2010
28 juin 2004 à 11:23
genial tu me sauve la vie, je te remercie.........

en revanche juste une derniere petite chose, a mon avis pour faire un truc bien il fodrai faire un AND ou XOR sur le mask et l'ico car

ca marche mais l'icon passer en bitmap est afficher noir tout autour du bitmap

comment pourait ton faire pour juste garder l'ico un AND entre iconinfo.hbmColor et iconinfo.hbmMask

merci de ta réponse
0
ShareVB Messages postés 2676 Date d'inscription vendredi 28 juin 2002 Statut Membre Dernière intervention 13 janvier 2016 26
29 juin 2004 à 17:41
salut

alors la il faut utiliser :
- GetObject pour obtenir des infos sur la bitmap et le masque (structure BITMAP)
- GetBitmapBits pour obtenir les données de la bitmap et du masque (cbBuffer=bmWidth * bmHeight * bmWidthBytes)
- tu fais un AND ou XOR entre les deux buffers et tu mets le résultat dans le buffer de la bitmap
- SetBitmapBits pour enregistrer les données dans le bitmap
(cbBuffer=bmWidth * bmHeight * bmWidthBytes) avec le buffer du bitmap

sans garantie... (sinon le mieux c encore de mettre tes icones en bitmap dans les ressources... moins de traitement)

sinon tous les handles que tu crées LoadIcon doivent être supprimer quand tu n'en as plus besoin...

voilà

ShareVB
0
youpiyoyo Messages postés 539 Date d'inscription vendredi 6 juin 2003 Statut Membre Dernière intervention 14 juillet 2010
29 juin 2004 à 18:03
t sur ke je doit faire ca car j'ai deja le mask bitmap et le bitmap....

iconinfo.hbmColor et le mask: iconinfo.hbmMask, donc le AND ou le XOR doit se faire mais je sais po comment je pense avec bitblit, mais je n'y suis po arriver ca marche po...

kan a mettre les ico en ressource est-ce k'il peut les mettre de façon permanente??? si oui cela m'interesse tres fortement de savoir komment....

si c possible je m'aventurerai a creer une DLL ki stocks les icos ou les bitmaps....

encore une fois je te remercie

je vais tester et si je trouve je te fais signe....
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
29 juin 2004 à 19:44
voila j'y suis arriver j'ai fais ca..:

HICON icon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICO_MAIN));
ICONINFO iconinfo={0};
BOOL ret = GetIconInfo(icon,&iconinfo);
HBITMAP iconbitmap = iconinfo.hbmColor, iconbitmapmask=iconinfo.hbmMask;

BITMAP bmpInfo;
GetObject(iconbitmap,sizeof(BITMAP),&bmpInfo);

HDC hDC=GetDC(hWnd);
HDC hdc_iconbitmap=CreateCompatibleDC(hDC);
HDC hdc_iconbitmapmask=CreateCompatibleDC(hDC);
ReleaseDC(hWnd, hDC);

HBITMAP oldbmphdc=(HBITMAP) SelectObject(hdc_iconbitmap, iconbitmap);
HBITMAP oldbmphdcmask=(HBITMAP) SelectObject(hdc_iconbitmapmask, iconbitmapmask);

BitBlt(hdc_iconbitmap,0,0,bmpInfo.bmWidth,bmpInfo.bmHeight,hdc_iconbitmapmask,0,0,SRCINVERT);

HBITMAP h_Bit = (HBITMAP) CopyImage(iconbitmap,IMAGE_BITMAP,(int)GetSystemMetrics(SM_CXMENUCHECK),(int)GetSystemMetrics(SM_CYMENUCHECK),0);

SetMenuItemBitmaps(hMenuPopup,ID_POPUP_ABOUT,MF_BYCOMMAND,h_Bit ,h_Bit);

je te remercie pour tous car sans toi j'y serais po arriver.....
0
Rejoignez-nous