-
How do u make a form translucent. And i mean not only the form itself, (allthought that wouldent be bad) but the entire form as a whole. So some of the background will show trough and same with the background forms if there are any.
And also, how do you make a form totally transparent, so u can only see the controls! (this 1 is easier!)
Thanks in advance (if possible),
InVitro
-
use bitblt
Use bitblt to copy the desktop image to the form or somert every time the form is moved. This would just show the controls on the form... It is possible, but I can't be arsed writing a sample at the moment. Just look into it, it is pretty easy to do...
Laterz
REM
-
How to make a form Transparent.
1. Code for a module
Code:
Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_TRANSPARENT = &H20&
Public Const SWP_FRAMECHANGED = &H20
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_SHOWME = SWP_FRAMECHANGED Or _
SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_NOTOPMOST = -2
Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter _
As Long, ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long
Add a CommandButton with following code
Private Sub Command1_Click()
SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT
SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, SWP_SHOWME
End Sub
3. The ShowInTaskbar property should be set to False and the BorderStyle to 0-None.
-
Thanks for the code, works great!
But that was only the easy part... anyone know how to make a form translucent so u can see controls in the background?
The form will only have images on it as controls.
But i want to make it so people can see some of their desktop. Kind of like trough glass. Ideas?
-
And now for the hard part, yes here it is:
Code:
Option Explicit
'USAGE:
' Private Sub Form_Load()
' SetWindowPos Me.hwnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, SWP_SHOWME
'End Sub
'Private Sub Form_Resize()
' GlassifyForm Me
'End Sub
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Declare Function GetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long) As Long
Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const SWP_FRAMECHANGED = &H20
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_SHOWME = SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_TOPMOST = -1
Public Sub Glassifyobj(obj As Object)
'0,02 s / 50 fps
If obj.AutoRedraw = False Then obj.AutoRedraw = True
Dim temp
'obj.Move -obj.Left, -obj.Top
obj.Visible = False
GlassifyForm obj.Parent
'obj.Move -obj.Left, -obj.Top
obj.Visible = True
DoEvents
temp = BitBlt(obj.hDC, 0, 0, obj.Width, obj.Height, obj.Parent.hDC, obj.Left, obj.Top, vbSrcCopy)
GlassifyForm obj.Parent
End Sub
Public Sub GlassifyForm(frm As Form)
frm.ScaleMode = vbPixels
Const RGN_DIFF = 4
Const RGN_OR = 2
On Error Resume Next
Dim outer_rgn As Long
Dim inner_rgn As Long
Dim wid As Single
Dim hgt As Single
Dim border_width As Single
Dim title_height As Single
Dim ctl_left As Single
Dim ctl_top As Single
Dim ctl_right As Single
Dim ctl_bottom As Single
Dim control_rgn As Long
Dim combined_Rgn As Long
Dim ctl As Control
Dim temp As Long
If frm.WindowState = vbMinimized Then Exit Sub
' Create the main form region.
wid = frm.ScaleX(frm.Width, vbTwips, vbPixels)
hgt = frm.ScaleY(frm.Height, vbTwips, vbPixels)
outer_rgn = CreateRectRgn(0, 0, 1000, 1000)
temp = GetWindowRgn(frm.hwnd, outer_rgn)
border_width = (wid - frm.ScaleWidth) / 2
title_height = hgt - border_width - frm.ScaleHeight
inner_rgn = CreateRectRgn(border_width, title_height, wid - border_width, hgt - border_width)
' Subtract the inner region from the outer.
combined_Rgn = CreateRectRgn(0, 0, 0, 0)
CombineRgn combined_Rgn, outer_rgn, _
inner_rgn, RGN_DIFF
'Create the control regions.
For Each ctl In frm.Controls
If ctl.Container Is frm And ctl.Visible Then
ctl_left = frm.ScaleX(ctl.Left, frm.ScaleMode, vbPixels) + border_width
ctl_top = frm.ScaleX(ctl.Top, frm.ScaleMode, vbPixels) + title_height
ctl_right = frm.ScaleX(ctl.Width, frm.ScaleMode, vbPixels) + ctl_left
ctl_bottom = frm.ScaleX(ctl.Height, frm.ScaleMode, vbPixels) + ctl_top
control_rgn = CreateRectRgn(ctl_left, ctl_top, ctl_right, ctl_bottom)
CombineRgn combined_Rgn, combined_Rgn, control_rgn, RGN_OR
End If
Next ctl
' Restrict the window to the region.
SetWindowRgn frm.hwnd, combined_Rgn, True
End Sub
The code is a bit old, I haven't used it in years so I don't know if it works... Try it ;)
-
That code is ALMOST perfect. But i was looking for something that leaves some of the form on itsef, like u said Kedeman.
'Alpha Blending'
anyone know a fast code that works on both win95 and 98?
-
I think it will work on win95 too, i meant that it won't work in nt or 2k
-
This is a method to make it to any degree of transparency (for 1 - 255).
http://www.planet-source-code.com/vb...txtCodeId=8015
-
Great link Megatron, but it noly works for windows 2000.
And im not sure about the other code, because it was said that it works for windows 98 only, not 95.
There seems to be no way! :(
-
Don't worry about that, you won't probably succeed anyway with alphablending, faster than using faketransparency. You could still do some cool effects by cutting regions...
-
Here is another one:
Code:
'This project needs 2 pictureboxes
'Picturebox1 must contain a picture with a lot of white pixels (we're going to use white as transparent color)
Private Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
Private Sub Form_Load()
Picture1.AutoSize = True
Picture1.ScaleMode = vbPixels
Picture2.ScaleMode = vbPixels
End Sub
Private Sub Picture2_Paint()
'If we don't call DoEvents first, our transparent image will be completely wrong
DoEvents
TransparentBlt Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, vbWhite
End Sub
-
Nice code, it is for transperency yet again... BUT!
I found some control under the references in my VB toolbar. Now its got a control called cooleffects or something like that.
I added it, looked at the object browser, and it had things like ALPHA & ALPHABLENDING.
It even had the % and everything. The problem is i dont know how to call it.
I tried doing something like
Dim PIC as ALPHABLENDING 'after i added it from the referenes.
Anways, if i do pic.
it will give me a couple things.
but there is nothing asking for the HWND or anything like that.
Does anybody know how to use those? I never use the references. Except 1 time for Microsoft scripting control.