We help IT Professionals succeed at work.

How to "mix" 2 icons in a new one ?

tradinfo
tradinfo asked
on
Hi,
I have 2 icons stored in a HICON.
I'd like to know how can I do to:
1. Create a third icon at runtime, using a mix of the 2 I have.
Example:
1st icon : a house :
/_\
|_|

2nd icon : an "x"

  x

3rd icon: a house and a x on the new icon:
/_\
|_x

Thanks for your help...

2. And in general, how can i manipulate an icon stored in a HICON like a bitmap ? Sample code appreciated...

Comment
Watch Question

Commented:
To mixe two image you must have one with transparency. Icon is not a gif, it's a bmp. So, you must read icon as bmp and manage yourself the transparancy with a specific color. For you second question, you could manage icon with bitmap function with an HICON, you must read the icon as an BMP.

Author

Commented:
a little sample code should be welcome to have a better understanding please...

Commented:
tradinfo,

if you are using MFC I would suggest using a CImageList. It has a member function SetOverlayImage. Use CImageList::Draw to show the icon and use the INDEXTOOVERLAYMASK macro for nStyle.
If you are not using MFC, you could still use the source code to figure out how to do it using the win32-api.

.:fl0yd:.

Author

Commented:
Maybe you should know how to do it with 2 HBITMAP ?
Points increased ...

Author

Commented:
question still open...
Let me know if you'd like a refund for this so I can move it to our PAQ at zero points and you can ask this again, since nothing has been added and this is a high-volume topic area, where few will find it.  You confirmed the need still exists 1/3/02, but nothing further has resulted.

Moondancer
Community Support Moderator @ Experts Exchange
Commented:
Sorry for not responding, somehow slipped my attention :(
Basically you have to do 4 operations:
1. use ImageList_Create( cx, cy, flags, cInitial, cGrow ) to create a list for your images (it's good for bitmaps as well as icons, masked and nonmasked)
2. use either ImageList_AddIcon( himl, hIcon ) or ImageList_Add( himl, hbmImage, hbmMask ) to put your icons/bitmaps under control of the image list
3. use ImageList_SetOverlayImage( himl, iImage, iOverlay ) to enable image iImage to be used as an overlay image
4. use ImageList_Draw( himl, i, hdcDst, x, y, fStyle ) to display it. Use fStyle and logically OR the return value of the INDEXTOOVERLAYMASK macro (|) with it. Your image i will be draw at position (x,y) into hdcDst with (fStyle >> 8) as an overlay image.
Hope that'll get you started. Let me know if you need further help.

.:fl0yd:.
Finalized, thanks for adding the additional response, although Asker hasn't responded to yours.  I had a Notif that Asker responded, but no comment found.
Moondancer - EE Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.