Click to See Complete Forum and Search --> : How to make a transparent Window ?
Hastur
November 22nd, 1999, 04:58 AM
Hi,
I'd like a transparent window, in order (for example) to make a non rectangular window. Perhaps it is not possible, but in this case, I suppose i should capture the background under the window to delete the part of the window that should be transparent, but how ? If I hide the window and capture the bitmap behind, it of course does an horrible flickering effect.
Thank you.
November 22nd, 1999, 09:56 AM
Unless you want to delve into the weird and wonderful to world of API to construct your own form there is no easy way to make your form transparent or even translucent while leaving the controls still showing. The method you mentioned of capturing the screen can be implemented effectively depending on how you do it, but for your problem - to make a non-rectangular window, there is an easier way.
That way is to use the SetWindowRgn API.
Here's the declaration:
Declare Function SetWindowRgn Lib "user32" Alias "SetWindowRgn" (byval hWnd as Long, byval hRgn as Long, byval bRedraw as Boolean) as Long
By defining a set of points using the POINTAPI structure and sending these to SetWindowRgn as a LONG, you effectively tell Windows where the boundaries of your form are, so you get an irregular shaped form.
HTH,
psiclone.
Hastur
November 22nd, 1999, 10:35 AM
In fact, I wish to enter the weird and wonderfull world of API programming :) And I suppose that Windows stores somewhere the bitmap that is behind each opened window, but where ?
Anyway, your answer is a good begining in my quest of strange forms, and thanks for having answered.
If someone knows if Windows really stores somwhere the bitmap behind a window like I suppose, and where, then I would really appreciate to have the answer.
Thxs by advance.
psiclone
November 22nd, 1999, 05:43 PM
Well, either way, you must use API. I have yet to find a simple solution to the problem. If you really want to capture the screen and draw the form on top (a procedure which I do not recommend), then you'll have to mess around with DCs and blitting. Here is a brief description of the methods you could use:
SCREEN CAPTURE
1) Capture the screen before the form loads.
2) Show the form.
3) Update the background every so often (system clock etc.)
4) Show the form as a picture whenever the user deactivates it and clicks the background.
This method is used for making screen savers where the screen is still visible, but image effects are added to it. If an irregular shaped window is all you want, setting the window region is a MUCH better option. The blitting method requires you to blit the desktop to a DC, blit the form on top of it in the DC, and then transfer it to the screen. Although the operation is quite fast and can be used to make simple games, full screen blits do tend to flicker.
Regards,
psiclone
Ravi Kiran
November 22nd, 1999, 11:42 PM
This, SetWindowRgn is precisely the way you create "hovering" controls also!. Only that you define your window region to include the sum of (rectangular) regions that comprise all your controls. It would be a little difficult to calculate, but not all that daunting though!
RK
Hastur
November 23rd, 1999, 02:20 AM
As you said, this method is very cpu time expensive, and there is still a matter : if I move the form, then the bitmap I captured before the form loads will not fit the new position. There's the same problem if I close a form that is behind my active form.
I'm sure there's a way to do that, look at the opening form of the game Outcast for example, or at the mpeg3 player KJofol.
Perhaps it is not possible with Visual Basic after all, perhaps the only method is effectively to capture the background every time an event is triggered in Windows' desktop (a form is moved, a from is closed), and then to refresh the form with it ; in that case only a fast language like C++ would (perhaps) be able to perform it without flickering.
Thank you anyway.
Hastur
November 23rd, 1999, 03:06 AM
I know it sounds weird to answer its own questions, but I finally found several sample codes which are exactly what I expected at the following url : http://www.extreme-vb.net/e2/form_effects.htm
Perhaps it will interest some of you.
Happy coding ;o)
Hastur
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.