Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Interface and Graphics > Transparent Mask


Reply
 
Thread Tools Display Modes
  #1  
Old 09-08-2004, 04:29 AM
Jonny's Avatar
Jonny Jonny is offline
Senior Contributor
 
Join Date: Jun 2003
Location: Birmingham, England, UK
Posts: 821
Default Transparent Mask


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?
Attached Images
File Type: jpg ASMEditorPro.jpg (72.6 KB, 31 views)
File Type: bmp 3.bmp (3.0 KB, 14 views)
__________________
Regards
John, jlsd.co.uk
Reply With Quote
  #2  
Old 09-08-2004, 08:03 AM
noi_max's Avatar
noi_max noi_max is offline
Still asleep...

Retired Leader
* Expert *
 
Join Date: Nov 2003
Location: IronForge
Posts: 2,694
Default

You could do two blits and use a mask, or use TransparentBlt 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.
__________________
~ Jason

Use [vb][/vb] tags when posting code :) || Search the forum and MSDN|| Check out the Posting Guidelines
Reply With Quote
  #3  
Old 09-08-2004, 12:27 PM
pikzel_R pikzel_R is offline
Contributor

* Expert *
 
Join Date: Jul 2004
Posts: 484
Default For masking "ASM Editor Pro" lettering - don't use anti-aliasing

Quote:
Originally Posted by noi_max
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..):
Attached Images
File Type: bmp ASM_Editor_Pro.bmp (3.0 KB, 10 views)
File Type: gif ASM_Editor_Pro.gif (187 Bytes, 54 views)
Reply With Quote
  #4  
Old 09-09-2004, 04:53 AM
eXeption's Avatar
eXeption eXeption is offline
Junior Contributor
 
Join Date: Aug 2004
Location: India
Posts: 270
Default

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!
__________________
"I think; therefore I am."
Reply With Quote
  #5  
Old 09-09-2004, 05:49 AM
Jonny's Avatar
Jonny Jonny is offline
Senior Contributor
 
Join Date: Jun 2003
Location: Birmingham, England, UK
Posts: 821
Default

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
Reply With Quote
  #6  
Old 09-09-2004, 07:15 AM
Jonny's Avatar
Jonny Jonny is offline
Senior Contributor
 
Join Date: Jun 2003
Location: Birmingham, England, UK
Posts: 821
Default Draw ControlBox

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?
__________________
Regards
John, jlsd.co.uk
Reply With Quote
  #7  
Old 09-09-2004, 07:31 PM
pikzel_R pikzel_R is offline
Contributor

* Expert *
 
Join Date: Jul 2004
Posts: 484
Default Subclass Form Titlebar

Quote:
Originally Posted by Jonny
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:
Code:
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...Bar_Sample.asp

Last edited by lebb; 09-10-2004 at 06:24 AM. Reason: Merged threads, so removed link to other thread (now this thread)
Reply With Quote
  #8  
Old 09-10-2004, 06:00 AM
eXeption's Avatar
eXeption eXeption is offline
Junior Contributor
 
Join Date: Aug 2004
Location: India
Posts: 270
Default

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!
__________________
"I think; therefore I am."
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->