Transparent Mask

Jonny
09-08-2004, 04:29 AM
I have a form that i have subclassed and used BitBlt to draw my custom title in the title bar. (Screenshot). It basically just paints the picture from a picture box.

What i would like to do is create a transparent mask that does not paint the black areas of the custom titlebar picture(screenshot also)

How would this be possible?

noi_max
09-08-2004, 08:03 AM
You could do two blits and use a mask, or use TransparentBlt (http://www.mentalis.org/apilist/TransparentBlt.shtml) and specify a transparent color.

I tried the latter with the image you provided, and due to the anti-aliasing of the letter graphics it didn't turn out too hot.

Also, I hear TransparentBlt is prone to memory leaks in older versions of Windows (95, 98). You may want to stick with two Bitblts and a mask (http://www.rookscape.com/vbgaming/GBeebe/bitblt.php).

pikzel_R
09-08-2004, 12:27 PM
I tried the latter with the image you provided, and due to the anti-aliasing of the letter graphics it didn't turn out too hot.
I agree with Noi_Max, you'll never get good masking with your original graphic, so I redid your bitmap to eliminate anti-aliasing. See attachment below (use the bmp, the gif is just for show..):

eXeption
09-09-2004, 04:53 AM
If u can't turn off Anti-aliasing,
Subclass it and get the original winow's titlebar blitted to a picturebox, print the text on it, and blit it back!

Jonny
09-09-2004, 05:49 AM
You could do two blits and use a mask, or us
Ok, iv'e done it!
Many thanks to noi_max for the TransparentBlt idea. Although it was astoundingly obvious.. i didnt know the function existed!

And thanks to pikzel_R for the crisp image. I've changed it now but i sorted the pic out with no anti-alias.

Thanks Guys
Jonny

Jonny
09-09-2004, 07:15 AM
Ok, ive searched the net and come up with nothing.

I have a subclassed form that i am custom-painting the caption-bar to. I am putting a custom gradient color over the top of the controlbox and i now need to force the controlbox to redraw. somehow. (or paint it myself).

and ideas?

pikzel_R
09-09-2004, 07:31 PM
Ok, ive searched the net and come up with nothing.
I have a subclassed form that i am custom-painting the caption-bar to. I am putting a custom gradient color over the top of the controlbox and i now need to force the controlbox to redraw. somehow. (or paint it myself).
and ideas?

Umm...how about you adjust your custom painting (WM_NCPAINT) so you don't draw off it in the first place?

Do you have any code that looks like:

Case vbFixedSingle
' 1 Fixed Single.
'Can include Control-menu box, title bar, Maximize button, and Minimize button.
'Resizable only using Maximize and Minimize buttons.
XBorder = GetSystemMetrics(SM_CXDLGFRAME)
DestHeight = GetSystemMetrics(SM_CYCAPTION) + 1
If FormControlBox = False Then
DestWidth = DestWidth - (XBorder * 2) + 9
Else
If FormMinButton = True Or FormMaxButton = True Then
DestWidth = DestWidth - (XBorder * 2) - _
(GetSystemMetrics(SM_CXSMSIZE) * 3) + 9
Else
DestWidth = DestWidth - (XBorder * 2) - _
(GetSystemMetrics(SM_CXSMSIZE) * 1) + 9
End If
End If

Case vbSizable
' 2 (Default) Sizable. Resizable using any of the optional border
'elements listed for setting 1.
XBorder = GetSystemMetrics(SM_CXDLGFRAME) + 1
DestHeight = GetSystemMetrics(SM_CYCAPTION) + 1
If FormControlBox = False Then
DestWidth = DestWidth - (XBorder * 2) + 9
Else
If FormMinButton = True Or FormMaxButton = True Then
DestWidth = DestWidth - (XBorder * 2) - _
(GetSystemMetrics(SM_CXSMSIZE) * 3) + 9
Else
DestWidth = DestWidth - (XBorder * 2) - _
(GetSystemMetrics(SM_CXSMSIZE) * 1) + 9
End If
End If

from this page:
http://www.thevbzone.com/modGradient.bas

Notice how the DestWidh is adjusted so it bypasses a control button paintover.
The other way is using masking, which was already covered in the last thread..

You can even get fancy and paint all the way around the control button, but there's really no reason to paint over it.

Some other references about subclassing the titlebar:
http://www.elitevb.com/content/01,0041,01/
http://www.vbaccelerator.com/home/VB/Code/Libraries/Subclassing/SSubTimer/VB6_Graduated_Title_Bar_Sample.asp

eXeption
09-10-2004, 06:00 AM
Take care using Transparentblt on a Win98 there is a memory leak exists (still unresolved, i think!), if u r using WinNT/2K/XP then use GdiTransparentBlt instead.
In ur problem this memleak may not matter, but if u r using it to blit a large image or a large number of them, it may cause a windows General Protection Fault!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum