I want to know if tou can make a form transparent, but not all the stuff in.
so you can see comboboxes, check boxes, list, exc.. with out a backround
Thanks
Printable View
I want to know if tou can make a form transparent, but not all the stuff in.
so you can see comboboxes, check boxes, list, exc.. with out a backround
Thanks
www.planetsourcecode.com is a miracle...... just do a search and you will find a lot of crap (good crap...or stuff) there.....including what you need.....
Good stuff here at the vbForums too. I came accross exactly what
you are looking for a while ago here. Search and i know you will
find it.
Start a Project, add a textbox and 2 buttons, then copy/paste this code. The background of the form will be transparent and only the 3 controls will be visible.
VB Code:
Option Explicit Private Declare Function CreateRectRgn Lib _ "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, _ ByVal X2 As Long, ByVal Y2 As Long) As Long Private Declare Function CombineRgn Lib _ "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, _ ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long Private Declare Function SetWindowRgn Lib _ "user32" (ByVal hWnd As Long, ByVal hRgn As Long, _ ByVal bRedraw As Boolean) As Long Private Declare Function DeleteObject Lib _ "gdi32" (ByVal hObject As Long) As Long ' Constants used by the CombineRgn function Private Const RGN_AND = 1 Private Const RGN_OR = 2 Private Const RGN_XOR = 3 Private Const RGN_DIFF = 4 Private Const RGN_COPY = 5 Private Sub Form_Activate() Dim rgnForm As Long, rgnCombined As Long Dim rgnControl As Long, x As Long Dim formWidth As Single, formHeight As Single Dim borderWidth As Single, titleHeight As Single Dim ctlLeft As Single, ctlTop As Single Dim ctlWidth As Single, ctlHeight As Single Dim ctl As Control ' Calculate the form area borderWidth = (Me.Width - Me.ScaleWidth) / 2 titleHeight = Me.Height - Me.ScaleHeight - borderWidth ' Convert to Pixels borderWidth = ScaleX(borderWidth, vbTwips, vbPixels) titleHeight = ScaleY(titleHeight, vbTwips, vbPixels) formWidth = ScaleX(Me.Width, vbTwips, vbPixels) formHeight = ScaleY(Me.Height, vbTwips, vbPixels) ' Create a region for the whole form rgnForm = CreateRectRgn(0, 0, formWidth, formHeight) rgnCombined = CreateRectRgn(0, 0, 0, 0) ' Make the graphical area transparent by combining the two regions x = CombineRgn(rgnCombined, rgnForm, rgnForm, RGN_DIFF) ' Make the controls visible For Each ctl In Controls ' Make the regions of controls whose container is the form visible If TypeOf ctl.Container Is Form Then ctlLeft = ScaleX(ctl.Left, vbTwips, vbPixels) + borderWidth ctlTop = ScaleX(ctl.Top, vbTwips, vbPixels) + titleHeight ctlWidth = ScaleX(ctl.Width, vbTwips, vbPixels) + ctlLeft ctlHeight = ScaleX(ctl.Height, vbTwips, vbPixels) + ctlTop rgnControl = CreateRectRgn(ctlLeft, ctlTop, ctlWidth, ctlHeight) x = CombineRgn(rgnCombined, rgnCombined, rgnControl, RGN_OR) End If Next ctl ' Set the clipping area of the window using the resulting region SetWindowRgn hWnd, rgnCombined, True ' Tidy up x = DeleteObject(rgnCombined) x = DeleteObject(rgnControl) x = DeleteObject(rgnForm) End Sub Private Sub Command2_Click() Unload Me End Sub
VB Code:
Const LWA_COLORKEY = &H1 Const LWA_ALPHA = &H2 Const GWL_EXSTYLE = (-20) Const WS_EX_LAYERED = &H80000 Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long Private Sub Form_Load() 'KPD-Team 2000 'URL: [url]http://www.allapi.net/[/url] 'E-Mail: [email][email protected][/email] Dim Ret As Long 'Set the window style to 'Layered' Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE) Ret = Ret Or WS_EX_LAYERED SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret 'Set the opacity of the layered window to 128 SetLayeredWindowAttributes Me.hWnd, 0, 128, LWA_ALPHA End Sub
Only works in 2000 and above though.
Here's a small skinning exmaple.
Woka