Important alert: (current site time 7/16/2013 4:16:19 AM EDT)
 

VB icon

Make Form Transparent.

Email
Submitted on: 2/27/1998
By: Kalani COM 
Level: Not Given
User Rating: By 104 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 59908
 
     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
Type POINTAPI
x As Long
Y As Long
End Type
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
		
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Make Form Transparent.
' Description:Makes a Form Trans Parent
' By: Kalani COM
'
' Side Effects:No Controls are Visible on the Form
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=816&lngWId=1'for details.'**************************************

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
Dim lpTL As POINTAPI, lpBR As POINTAPI
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

4/13/1999 9:50:00 AMJoe

Hi, very nice code, exactly what i've been searching for...but how can i let objects leave visible on the form ??? they also disapear...
Thanks
Joe
(If this comment was disrespectful, please report it.)

 
4/15/1999 1:52:00 AMKlendathu

I agree with Joe. WE WANT TO BE ABLE TO SEE THE OBJECTS!!!!
(If this comment was disrespectful, please report it.)

 
4/25/1999 12:49:00 PMGEEZA

These are simple Set Window Region APIs, i have messed with them myself many times, and the only way i know of to show the objects in the form is to Set a VISIBLE region for the object. I did it for a Close button
Ask and i might be able to find the code
(If this comment was disrespectful, please report it.)

 
4/26/1999 9:39:00 AMJohn

If you would like to have the objects visible Visit Code SetTranparent written by
satin katiyar at this site itself.I fully Agree with him.
(If this comment was disrespectful, please report it.)

 
5/1/1999 2:54:00 PMMike

this seems like a really cool code. i'm new at
programming. can u email me exactly how to
code your code. where do i put the declarations.
thanks.
(If this comment was disrespectful, please report it.)

 
5/29/1999 11:56:00 AMMETEX

It's cool.Thank you.very graet thing that you do.Thanks
(If this comment was disrespectful, please report it.)

 
6/14/1999 11:35:00 AMWiz

im not sure how to put in your code but would like to try it.. if you could explain how i would put it in
(If this comment was disrespectful, please report it.)

 
6/18/1999 7:13:00 PMChris

Out of curiosity, when I place MakeTransparent(form1) in my form load procedures I get an error. Can you tell me what im doing wrong? Thanks!
(If this comment was disrespectful, please report it.)

 
6/19/1999 10:51:00 AMHATCHET

Chris,
When you put "Form1" inside of the parenthases, it things you want to return a value. By definition, a Sub can't return anything. Take out the Paren's and it should work fine:

MakeTransparent Form1

HATCHET
(If this comment was disrespectful, please report it.)

 
7/9/1999 5:55:00 AMdpc

Wonderful bit of code.
Is there a way to make
the form visible again though?

I'm working on figuring it out now, but am fairly new to the API.
(If this comment was disrespectful, please report it.)

 
7/11/1999 12:42:00 AMAlex

Can someone send me the project file of this too me? Thanks
(If this comment was disrespectful, please report it.)

 
7/17/1999 6:35:00 PMCLOUD

I HAVE NOT I DEIA HOW TO WORK THIS COAD
somone help
(If this comment was disrespectful, please report it.)

 
7/18/1999 5:50:00 PMbob

First, figure out how to spell right.
(If this comment was disrespectful, please report it.)

 
7/28/1999 7:08:00 PMWater

Thats right
(If this comment was disrespectful, please report it.)

 
8/15/1999 3:55:00 AMWilliam Floor

This code can be much smaller!!!
Just 1 line of code, with the same effect.
The Form and Controls are transparent:
Form1.Visible = False
Now the form seems to be transparent, but it
is actually invisible.
(If this comment was disrespectful, please report it.)

 
9/1/1999 4:57:00 PMAustin Agarwal

Every one who wants to see the objects on the form, email me, i have a different code but its much better,
Austin6865@aol.com
http://Austinaa.click2site.com
(If this comment was disrespectful, please report it.)

 
10/4/1999 1:11:00 PMUriel Hernández Robledo

Por favor, si tienes el OCX, envíamelo
Thank you.

(If this comment was disrespectful, please report it.)

 
11/13/1999 6:58:00 PMKalani COM

Re: Uriel Hernandez Robledo

No hice un OCX pero el código proveió (y VB5+) de usted puede compilar esto en sus el propio. Perdón mi español horrible.


(If this comment was disrespectful, please report it.)

 
11/16/1999 2:13:00 AMRevenant

HEY!! I"VE SEEN THIS CODE!! IT"S EXACTLY THE SAME!! How dare you to steal codes from others and then credit yourself for 'creating' it!!! LAMERS!!
(If this comment was disrespectful, please report it.)

 
11/16/1999 9:27:00 PMGeorge

Hi,I am doing a project whereby I must display a waveform while playing a wav file in Visual Basic 6.0, Can you help?
Thanks In Advance.
(If this comment was disrespectful, please report it.)

 
11/19/1999 9:51:00 AMShadow

I must find out how to make the objects visible. I have tried the code for making a transparent color on a form but that does not work. Could use some help.
Thanks, e-mail me if you have a solution.
(If this comment was disrespectful, please report it.)

 
12/25/1999 11:46:05 PMzdsdsadasd


(If this comment was disrespectful, please report it.)

 
1/30/2000 4:47:17 AMofer

I have to make an unrectangle form
(a form that I can design by myself)
can you help with some advice
many thenks
Ofer
(If this comment was disrespectful, please report it.)

 
2/26/2000 1:49:41 PMNick

You new people are too picky. Beggers can't be choosers. Experiment a bit get some books i recommend a book called "Guide To The Win 32 Api" mainly for vb4.0 but it covers every api, except for communications which is basically self explanitory. The author's name is "Dan Appleman" i would get the isbn # but im too lazy. Read Read Read Read! Thats All you need to do!
(If this comment was disrespectful, please report it.)

 
6/12/2000 5:28:52 PMJeffrey C. Tatum

I don't understand you people. We the programmers post code for those who might want it, and learn from it. How dare you complain about it. It's people who critisize the programmers, that makes programmers now want to help. Give them credit where credit is due. THEY spend time writing the codes for you who cant write them. Show a little respect. And for Kalani, nice code. Keep up the good work.
(If this comment was disrespectful, please report it.)

 
9/22/2001 8:31:05 PMchris

great work here, but for some reason i find that when a form is made transparent its then unable to change the mousepointer! any solutions?
(If this comment was disrespectful, please report it.)

 
9/22/2001 8:33:44 PMmarshy

Great work. However, one problem i find when making forms transparent is that it prevents you from changing the mouse pointer! Any help much apperitiated
(If this comment was disrespectful, please report it.)

 
4/23/2002 2:28:05 PMScott68

Add these to your form code:

Private Sub Form_Load()
MakeTransparent Me
End Sub

Private Sub Form_Resize()
MakeTransparent Me
End Sub

Works great for me!
Neat code, Thanks!
(If this comment was disrespectful, please report it.)

 
8/21/2003 10:23:40 PM

good code with smart
(If this comment was disrespectful, please report it.)

 
7/24/2004 3:29:28 AMJeroen van de Ven

Oh my god this code is rated 5.5 globes??

Howd they do that??

(If this comment was disrespectful, please report it.)

 

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.