|
-
Sep 22nd, 2009, 03:09 AM
#1
Thread Starter
Lively Member
Alpha blended non rectangular form in VB6
Hello guys,
I did ask this question in another forum already, but got no answer...
Hope that here are some pros, who can help me. 
I did use following example code as base for my project:
http://www.activevb.de/cgi-bin/uploa...oad.pl?id=2126
It loads an alpha blended png file and creates a splash screen with it.
It looks really gorgeous! 
But now I have two problems:
* All controls on the form are invisible.
* I am not able to add additional grafics to the "splash screen"
I also found examples to merge two grafic files together, but I like to add these grafics on some user events - that means, that the splash screen was already created. And I don't know how to apply addtional grafics to that window.
Right now I am presenting this addtional grafical elements in a second form above the so call splash screen (as you can see, I am not using it as splash screen ) - but this is a pretty ugly programming style, since form movement creates unattractive effects - even with subclassing techniques.
Is there a way to add controls ot that window and merge additional grafics to the form after it was created?
Or is there another way to create an alpha blended non rectangular form, which does not show the mentioned issues?
I found a nice thread in this forum here, which has the same topic:
http://www.vbforums.com/showthread.php?t=463045
Unforunately the example has the problem, that the form can't be moved.
Addtionally there is a "black boarder" effect, if the example is launched - this does not happen in my activevb example.
- But maybe both examples can be combinded somehow...
I really appreciate your help!
-
Sep 22nd, 2009, 08:23 AM
#2
Re: Alpha blended non rectangular form in VB6
Welcome to the forums.
The short answer is no. If there was a solution it would have been in use since Win2K was released. When you use UpdateLayeredWindow, you are passing all drawing to the operating system and the only thing it draws is the bitmap you supplied to that API. So, this means you have to update the bitmap to make controls "visible", but drawing the controls onto the bitmap each time their graphical state changes is unreasonable IMO.
The hack to use 2 forms, where one is overlapped over another is a standard workaround, but has its own issues too as you are discovering.
You can add additional graphics to any window using UpdateLayeredWindow. However, once you change the graphics you have to call UpdateLayeredWindow again and pass the updated bitmap. This does mean you have to have knowledge with drawing to 32bit bitmaps that use the alpha channel (can be challenging using GDI APIs since they are not alpha-channel aware, but GDI+ is, though some people find it harder to use).
Those APIs were designed to support "small, short-lived" windows and were not designed to support complete applications.
A slightly less attractive workaround is to use window regions to shape the form. Window regions prevent all the issues you are describing, but you loose the smoothness of alphablended edges. Comparing UpdateLayeredWindow to window regions is like comparing PNG to GIF; you can get jaggies on the edges with the latter.
-
Sep 22nd, 2009, 10:24 AM
#3
Thread Starter
Lively Member
Re: Alpha blended non rectangular form in VB6
Hi LaVolpe, thank you for your answer.
 Originally Posted by LaVolpe
Welcome to the forums.
Thanks. Hope it will take me further. 
The short answer is no. If there was a solution it would have been in use since Win2K was released. When you use UpdateLayeredWindow, you are passing all drawing to the operating system and the only thing it draws is the bitmap you supplied to that API. So, this means you have to update the bitmap to make controls "visible", but drawing the controls onto the bitmap each time their graphical state changes is unreasonable IMO.
Ok. That explains, why I was not able to find any satisfying examples...
How can I draw controls onto a bitmap?
You can add additional graphics to any window using UpdateLayeredWindow. However, once you change the graphics you have to call UpdateLayeredWindow again and pass the updated bitmap. This does mean you have to have knowledge with drawing to 32bit bitmaps that use the alpha channel (can be challenging using GDI APIs since they are not alpha-channel aware, but GDI+ is, though some people find it harder to use).
I tried this with the code from my example. But the window was not updated and the GDI+ instance could not be shutdown correctly afterwards.
Is there a clean example available here? Or is it possible for you to give me a short one? (if I can ask - I don't want to steal your time)
Those APIs were designed to support "small, short-lived" windows and were not designed to support complete applications.
I like to write kind of a small widget, with just a few setting controls.
Since the functionality of those widgets is mostly not very important, the appearance has to iron it out - with a lot of beautiful sight and pleasure to look at. 
A slightly less attractive workaround is to use window regions to shape the form. Window regions prevent all the issues you are describing, but you loose the smoothness of alphablended edges. Comparing UpdateLayeredWindow to window regions is like comparing PNG to GIF; you can get jaggies on the edges with the latter.
Yes, I was thinking about using the window regions for the settings window, because of the controls. It depends on how hard it is, to draw controls onto a bitmap.
The most important for me would be, to get a short example, how it is possible to apply new grafics onto an existing layered window.
Btw: If I am satisfied with my project, I will release it for free - so you can also benefit from it!
-
Sep 22nd, 2009, 10:45 AM
#4
Re: Alpha blended non rectangular form in VB6
Unfortunately, drawing on bitmaps with the alpha-channel in play is not straightforwared and does have a learning curve. The basics should be addressed first. Here are some things you will have to read up on to begin with
1. Learn how to create/use/destroy a memory DC
2. Learn how to create/use/destroy a memory bitmap
3. If not using GDI+, learn how to premultiply RGB values against the Alpha value
4. If using GDI+, learn how to use GDI+ for basic drawing and for drawing strings
After you are comfortable with the above, then providing examples would be more meaningful. Drawing controls onto the 32bit bitmap is a bit complicated but doable.
Here is a site that has good info on bitmaps in general and basics on manipulating them. 32bit bitmaps for alpha-channel processing are not addressed, but the site has some very good basics.
You also may want to look at some of these examples on planetsourcecode.
Edited: Searching this forum and googling for "UpdatedLayeredWindow" and "VB6" should return even more examples.
Last edited by LaVolpe; Sep 22nd, 2009 at 10:53 AM.
-
Sep 22nd, 2009, 01:05 PM
#5
Thread Starter
Lively Member
Re: Alpha blended non rectangular form in VB6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|