Bitmaps or Icons on Buttons (transparent backgrounds)
Alix -- AARGUELL@sys1.com
Wednesday, May 15, 1996
Visual C++ 4.0, Win95
In my application, I have several places where I would like to display
bitmaps and/or icons on buttons.
Is there anyway to make the background of the bitmap/icon transparent so
that the color of the button face shows through?
I have erased the areas surrounding the actual picture but once it is on
the button, the bitmap background is white and the icon background is
the teal green! I can actually paint the background gray so that it
matches in most case, I would like it to match no matter what system
colors the user selects!
Any help would be greatly appreciated.
Alix Arguelles
System One Amadeus
AARGUELL@SYS1.COM
Chris Scott -- cscott@aceltd.com
Saturday, May 18, 1996
[Mini-digest: 2 responses]
>> Visual C++ 4.0, Win95
>> I have erased the areas surrounding the actual picture but once it is on
>> the button, the bitmap background is white and the icon background is
>> the teal green! I can actually paint the background gray so that it
>> matches in most case, I would like it to match no matter what system
>> colors the user selects!
It looks like you have already solved the hard part -
drawing transparently. To match up the background, simply
paint the button face using the current 3d face color,
which you can get with a call to the SDK function
GetSysColor(COLOR_3DFACE).
Chris S.
SendMessage(WM_STUFF_NOBODY_WANTS_TO_READ_GOES_HERE);
-----From: Sam Saab
Use BM_SETIMAGE and use an icon instead of a bitmap. For more detailed
information see Windows developer's journal, june 1996 Tech Tips column.
Hope this helps
SAM
Grant Shirreffs Great Elk -- Grant.S@greatelk.co.nz
Monday, May 20, 1996
[Mini-digest: 2 responses]
The icon should be easy enough, shouldn't it? Just use DrawIcon. For
the bitmap, what I normally do is design it like an icon, with something
lurid like lime green in the 'transparent' areas. Then, instead of using
LoadBitmap, use FindResource/LoadResource/LockResource, find the palette
info in the BITMAPINFO, change lime green (RGB(0,0,255)) to
GetSysColor(COLOR_BTNFACE) and then use SetDIBits create a bitmap.
Longwinded, I suppose, but it's the kind of thing you only have to write
once.
Hope this helps.
Grant Shirreffs
-----From: Don.Irvine@net-tel.co.uk
> Is there anyway to make the background of the bitmap/icon transparent so
> that the color of the button face shows through?
Look at the function AfxLoadSysColorBitmap in bartool.cpp. This is
undocumented, but will do what you want.
Don
DORIE@ris.risinc.com
Monday, May 20, 1996
[Mini-digest: 4 responses]
Look at the article titled "New Windows 95 Styles Make Attaching
Bitmap to Button Easier." It has sample code as well as helpful(and
easy) information. One note on the subject is that when they show
you how to do this with an icon it is using the 32x32 version of the
icon not the 16x16. If you want to use a 16x16 version of the icon
you need to use LoadImage instead of LoadIcon. Make sure the icon
has a trasparent background when you create it. It's really very
simple, check it out.
-----From: Scott Jones
...Or, if you only care about Win 95 (and presumably NT 4.0), you can use
LoadImage() instead (pass it the LR_LOADMAP3DCOLORS flag and it will
essentially perform all of the above steps for you).
--
Scott Jones
Software Engineer
Netscape Communications Corp.
-----From: arash@newton.apple.com (Arash Afrakhteh)
There is a sample code in MSDN that draws transparent bitmaps. It is a
class called "CTransBmp" which is part of MFCCLIP sample code discussed in
"MFC Tips for Copying Pasting, Blting, and Creating Owner-Drawn List Boxes"
article.
Hope it helps,
-arash
-----From: "Frederic Steppe"
As long as you are targeting Windows 95 platforms, you may use the LoadImage
function to load an icon, cursor, or bitmap, and specify the following flags :
LR_LOADMAP3DCOLORS : All gray, light gray and dark gray pixels will be mapped
to system 3D colors (usually the same colors)
LR_LOADTRANSPARENT : all pixels being the same color as the first one (upper
left) will be changed to COLOR_WINDOW (usually white)
LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT : all pixels being the same color as
the first one (upper left) will be changed to COLOR_3DFACE (usually gray)
Frederic Steppe (frederics@msn.com)
Alex McLeod -- mcleod@dki.com
Tuesday, May 21, 1996
If you do a search on the MSDN disks for the word "CTransBmp" you will find
an article which provides a reasonable class for drawing bitmaps
transparently (beware the printing issues noted in the article!, if that is
a concern!)
This class can be modified to either assume a specific color for the
'transparent' color or to pluck the 'transparent' color from a given
position in the bitmap that is being drawn (typically one of the corners).
As it exists it does one or the other of these, but I don't remember which!
The article's example is MFCCLIP and the article was written by Nigel
Thompson
Microsoft Developer Network Technology Group
Created: July 19, 1994
Beware a resource leak which I think requires:
// Nuke any existing mask
if (m_hbmMask)
::DeleteObject(m_hbmMask);
in the class's destructor!
Alex
----------
>From: owner-mfc-l
>To: mfc-l
>Subject: RE: Bitmaps or Icons on Buttons (transparent backgrounds)
>Date: Monday, May 20, 1996 9:52AM
>
>[Mini-digest: 2 responses]
>
>The icon should be easy enough, shouldn't it? Just use DrawIcon. For
>the bitmap, what I normally do is design it like an icon, with something
>lurid like lime green in the 'transparent' areas. Then, instead of using
>LoadBitmap, use FindResource/LoadResource/LockResource, find the palette
>info in the BITMAPINFO, change lime green (RGB(0,0,255)) to
>GetSysColor(COLOR_BTNFACE) and then use SetDIBits create a bitmap.
> Longwinded, I suppose, but it's the kind of thing you only have to write
>once.
>
>Hope this helps.
>
>Grant Shirreffs
>
> -----From: Don.Irvine@net-tel.co.uk
>
>> Is there anyway to make the background of the bitmap/icon transparent so
>
>> that the color of the button face shows through?
>
>Look at the function AfxLoadSysColorBitmap in bartool.cpp. This is
>undocumented, but will do what you want.
>
>
>Don
| Вернуться в корень Архива
|