VB icon

Make Form Transparent.

Submitted on: 1/1/2015 1:36:00 PM
By: Kalani COM (from psc cd)  
Level: Not Given
User Rating: By 104 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 2148
     Makes a Form Trans Parent

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'Windows API/Global Declarations for :Make Form Transparent.
Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRECT As RECT) As Long
Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRECT As RECT) 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 CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Public Const RGN_AND = 1
Public Const RGN_COPY = 5
Public Const RGN_DIFF = 4
Public Const RGN_OR = 2
Public Const RGN_XOR = 3
x As Long
Y As Long
End Type
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
' Name: Make Form Transparent.
' Description:Makes a Form Trans Parent
' By: Kalani COM (from psc cd)
' Side Effects:No Controls are Visible on the Form

Public Sub MakeTransparent(frm As Form)
'This code was takin from a AOL Visual Basic
'Message Board. It was submited by: SOOPRcow
Dim rctClient As RECT, rctFrame As RECT
Dim hClient As Long, hFrame As Long
'// Grab client area and frame area
GetWindowRect frm.hWnd, rctFrame
GetClientRect frm.hWnd, rctClient
'// Convert client coordinates to screen coordinates
lpTL.x = rctFrame.Left
lpTL.Y = rctFrame.Top
lpBR.x = rctFrame.Right
lpBR.Y = rctFrame.Bottom
ScreenToClient frm.hWnd, lpTL
ScreenToClient frm.hWnd, lpBR
rctFrame.Left = lpTL.x
rctFrame.Top = lpTL.Y
rctFrame.Right = lpBR.x
rctFrame.Bottom = lpBR.Y
rctClient.Left = Abs(rctFrame.Left)
rctClient.Top = Abs(rctFrame.Top)
rctClient.Right = rctClient.Right + Abs(rctFrame.Left)
rctClient.Bottom = rctClient.Bottom + Abs(rctFrame.Top)
rctFrame.Right = rctFrame.Right + Abs(rctFrame.Left)
rctFrame.Bottom = rctFrame.Bottom + Abs(rctFrame.Top)
rctFrame.Top = 0
rctFrame.Left = 0
'// Convert RECT structures to region handles
hClient = CreateRectRgn(rctClient.Left, rctClient.Top, rctClient.Right, rctClient.Bottom)
hFrame = CreateRectRgn(rctFrame.Left, rctFrame.Top, rctFrame.Right, rctFrame.Bottom)
'// Create the new "Transparent" region
CombineRgn hFrame, hClient, hFrame, RGN_XOR
'// Now lock the window's area to this created region
SetWindowRgn frm.hWnd, hFrame, True
End Sub

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.