Re: Icons from resource file to button face???

From: Mark Durrenberger (durrenm_at_yahoo.com)
Date: 05/05/04


Date: Tue, 4 May 2004 20:50:39 -0400

Mike, I found your site earlier today and started the intro to classes
tutorial - great stuff. Thanks for the help.
Mark

-- 
_________________________________________________________
Mark Durrenberger, PMP
Principal, Oak Associates, Inc, www.oakinc.com
"Advancing the Theory and Practice of Project Management"
________________________________________________________
The nicest thing about NOT planning is that failure
comes as a complete surprise and is not preceded by
a period of worry and depression.
- Sir John Harvey-Jones
"Mike D Sutton" <EDais@mvps.org> wrote in message
news:%23xvaIbiMEHA.2592@tk2msftngp13.phx.gbl...
> > Using the following code, I am attempting to put an icon (.ico) on to a
> > command bar button.
> >
> > The code works fine if I work with a bitmap (vbResBitmap instead of
> > vbResIcon) however,
> > bitmaps are not transparent, icons are. I want the "background" of my
icons
> > to take on the appropriate bacground color (buttonface for example)
> >
> > It appears that I cannot put icons on the clipboard so the
> > "clipboard.setdata" line pukes.
> >
> > So how do I get an icon from a resource file to my button face?
> > Is there a way around the clipboard?
>
> Have a look at this post and grab the code libraries from that including
ChromaBlt() off my site, although you won't actually be
> using it for the Icon->Bitmap conversion the library still requires it to
be there (you could remove this and modCopyBitmap.bas with
> a conditional compile argument though if you find it's cluttering up your
project):
>
http://groups.google.co.uk/groups?selm=u5FEkt5LEHA.2632%40TK2MSFTNGP09.phx.gbl
>
> Replace the modIconHelper.bas library with this new version below, which
includes an HICON to HBITMAP converter for you:
> http://www.mvps.org/EDais/Code/Libraries/Graphics/modIconHelper.bas
>
>
> Drop a third picture box on the form and here's the new code to test it
all:
>
> '***
> Private Declare Function DestroyIcon Lib "User32.dll" (ByVal hIcon As
Long) As Long
> Private Declare Function DeleteObject Lib "GDI32.dll" (ByVal hObject As
Long) As Long
>
> Private Sub IconConverstionTest()
>     Dim hIcon As Long
>     Dim IconPic As StdPicture
>
>     ' Requires:
>     '   modIconHelper     - For conversion from HBITMAP to HICON
>     '    +- modChromaBlt  - For mask extraction
>     '    +- modCopyBitmap - For DDB copy
>     '   modOLEPicture     - For conversion from HICON to StdPicture
>
>     ' Create an icon from the picture, making any magenta pixels
transparent
>     hIcon = BitmapToIcon(Picture1.Picture.handle, vbMagenta)
>     Set IconPic = GDIToPicture(hIcon)
>
>     If (IconPic Is Nothing) Then
>         Call DestroyIcon(hIcon) ' Clean up API icon handle to prevent
resource leaks
>     Else ' At this point IconPic owns the API icon handle so we don't need
to kill it
>         Set Picture2.Picture = IconPic
>     End If
> End Sub
>
> Private Sub BitmapConverstionTest()
>     Dim hBMP As Long
>     Dim BmpPic As StdPicture
>     Dim hIcon As Long
>
>     ' Requires:
>     '   modIconHelper     - For conversion from HICON to HBITMAP
>     '   modOLEPicture     - For conversion from HBITMAP to StdPicture
>
>     ' Create an Bitmap from the icon, making any transparent pixels
magenta
>     hBMP = IconToBitmap(Picture2.Picture.handle, vbMagenta)
>     Set BmpPic = GDIToPicture(hBMP)
>
>     If (BmpPic Is Nothing) Then
>         Call DeleteObject(hBMP) ' Clean up API Bitmap handle to prevent
resource leaks
>     Else ' At this point BmpPic owns the API Bitmap handle so we don't
need to kill it
>         Set Picture3.Picture = BmpPic
>     End If
> End Sub
>
> Private Sub Command1_Click()
>     Call IconConverstionTest
>     Call BitmapConverstionTest
> End Sub
> '***
>
> Hope this helps,
>
>     Mike
>
>
>  - Microsoft Visual Basic MVP -
> E-Mail: EDais@mvps.org
> WWW: http://www.mvps.org/EDais/
>
>

Loading