[comp.windows.ms.programmer] How to display an icon from a .ICO file -- not a resource ?

heath@ncrcae.Columbia.NCR.COM (Robert Heath) (03/05/91)

How does one read in and display the contents of a .ICO file within
a Win app ? (I realize the normal way is to compile in a .ICO as a resource via 
"rc".)   I want to be able to have  the user specify which .ICO file 
to display at runtime.  I can't seem to find out how to do this in
the literature.

	Robert Heath

mike@wang.com (Mike Sullivan) (03/11/91)

heath@ncrcae.Columbia.NCR.COM (Robert Heath) writes:

>How does one read in and display the contents of a .ICO file within
>a Win app ? (I realize the normal way is to compile in a .ICO as a resource via 
>"rc".)   I want to be able to have  the user specify which .ICO file 
>to display at runtime.  I can't seem to find out how to do this in
>the literature.

>	Robert Heath

Back when _I_ was a windows weenie I wrote a routine called IconLoad
which took a filename.  It opened the file, read a header ( which is 
defined in the literature ) determined whether it really was an icon
and what size icon, and then read rest of the file into bitmaps.

I also wrote IconDraw and IconMove.  The other advantage that doing 
own routines gave me is that I was able to colorize them.  DrawIcon
always drew them in B&W for some reason.  (IconMove allowed me to 
drag an Icon around on the screen.  Performance was quite reasonable.

Anyway the secret to drawing the Icon is to first draw the mask in the
desired background color using BitBlt with SRCAND.  

Then draw the bits using the desired foreground color using BitBlt 
and SRCINVERT.

-- 
  ________________________
 /                    __  \  | Michael J. Sullivan    |ec.lec.tic adj Choosing
| \  \  /  /\  |\ |  /  `  | | Wang Laboratories Inc. |or consisting of what 
|  \/ \/  /--\ | \|  \__T  | | mike@WANG.COM	      |appears to be the best 
 \________________________/  | 			      |from diverse sources.