Mar 31st, 2006, 08:32 AM
#1
Making A Form Transparent (But with visible controls)
To make form transparent, but controls visible:
VB Code:
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 Const GWL_STYLE = (-16)
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Sub Form_Load()
Me.BackColor = vbCyan
SetWindowLong Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED
SetLayeredWindowAttributes Me.hwnd, vbCyan, 0&, LWA_COLORKEY
End Sub
It actually just makes anything coloured vbCyan to become transparent.
Last edited by bushmobile; Apr 12th, 2006 at 05:31 AM .
Mar 31st, 2006, 08:51 AM
#2
Re: Making A Form Transparent
Mar 31st, 2006, 12:26 PM
#3
Re: Making A Form Transparent
SetLayeredWindowAttributes is supported only in Win2K and later.
This code may not work on Win9x/Me. I haven't tested it though.
Mar 31st, 2006, 12:42 PM
#4
Re: Making A Form Transparent
I have no idea about ME (never used it), but the only problem I had with this code on Win98 was with labels.
They didn't show up at all. I have to replace them with textboxes that looked like they were labels.
Mar 31st, 2006, 01:18 PM
#5
Re: Making A Form Transparent
Not supported in 98 or ME. Only Windows 200/XP/Vista.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 31st, 2006, 02:34 PM
#6
Re: Making A Form Transparent
Justed tested it in Win98.
Run-time error '453': Can't find DLL entry point SetLayeredWindowAttributes in user32
Further reading: http://www.codeproject.com/w2k/QDWndTransparency.asp
Mar 31st, 2006, 03:18 PM
#7
Re: Making A Form Transparent
From your post #4
Requires Windows 2000 or later; Win9x/ME: Not supported
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 31st, 2006, 03:34 PM
#8
Re: Making A Form Transparent
I know. But Hack mentioned the 'only' problem he had on Win98 is with labels.
That means he is able to run this code in Win98. Isn't it ?
PS: I don't have VB in Win98. I run it from compiled exe.
Mar 31st, 2006, 03:42 PM
#9
Re: Making A Form Transparent
If you make a very basic exe then you should only need the msvbvmm60.dll on your 98 system and the SetLayeredWindowAttributes is in th user32 kernal so it should run but give you an error in the user32 dll.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 31st, 2006, 03:47 PM
#10
Re: Making A Form Transparent
That's exactly my point.
That code references the API at compiletime. It doesn't uses a LoadLibrary like the link I posted in post #6.
So, Hack should get an error 453 just after doubleclicking the exe.
But he is probably able to run it in Win98. (as he said in post#4)
Originally Posted by
Hack
... but the only problem I had with this code on Win98 was with labels.
How ?
Mar 31st, 2006, 03:49 PM
#11
Re: Making A Form Transparent
Error trapping for 453 and handling it so the program would continue to run and not crash?
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 31st, 2006, 03:51 PM
#12
Re: Making A Form Transparent
Yes. May be.
[SLAP]iPrank[/SLAP]
Apr 10th, 2006, 05:59 PM
#13
Addicted Member
Re: Making A Form Transparent
i really like it, one question, if i had a picture box i wanted transparent can i make it so the picture box is transparent but the form isn't so i can see whats on the form. Otherwise its great!
Resizing
System Balloons
If your question is answered, please mark the thread resolved by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button.
Remember to rate a post if you find it helpful
Apr 10th, 2006, 06:01 PM
#14
Re: Making A Form Transparent
Try passing the picturebox handle to the APIs.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Apr 12th, 2006, 05:34 AM
#15
Re: Making A Form Transparent (But with visible controls)
This will only work for top-level windows so passing the hWnd of the child won't do anything. If you replace:
VB Code:
Me.BackColor = vbCyan
' with
Picture1.BackColor = vbCyan
Then just the picturebox will be made transparent.
Apr 12th, 2006, 06:45 AM
#16
Hyperactive Member
Re: Making A Form Transparent (But with visible controls)
Nice Code.
How do i undo it though?
KAZAR
The Law Of Programming:
As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
__________________________________
www.startingqbasic.co.uk
Apr 12th, 2006, 07:10 AM
#17
Re: Making A Form Transparent (But with visible controls)
The easiest way is probably to remove the WindowStyle:
VB Code:
Private Sub Command1_Click()
Dim lStyle As Long
lStyle = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
If (lStyle And WS_EX_LAYERED) = WS_EX_LAYERED Then SetWindowLong Me.hwnd, GWL_EXSTYLE, lStyle Xor WS_EX_LAYERED
Me.BackColor = vbButtonFace
End Sub
Apr 12th, 2006, 07:26 AM
#18
Addicted Member
Re: Making A Form Transparent (But with visible controls)
changing the form backcolor and just the picture box to cyan did not work, it still goes throught the form also.
Resizing
System Balloons
If your question is answered, please mark the thread resolved by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button.
Remember to rate a post if you find it helpful
Apr 12th, 2006, 07:40 AM
#19
Re: Making A Form Transparent (But with visible controls)
it still goes throught the form also
What do you mean by that?
Do not set the form's backcolor to vbCyan, only set the picturebox's backcolor to vbCyan:
Attached Images
Apr 12th, 2006, 12:15 PM
#20
Hyperactive Member
Re: Making A Form Transparent (But with visible controls)
Sorry to cross between this thread and vba, but you can use this in vba as well if you use the following code:
VB Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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 Const GWL_STYLE = (-16)
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Dim formhandle as Long
Private Sub Form_Load()
formhandle = FindWindow(vbNullString, Me.Caption)
SetWindowLong formhandle, GWL_EXSTYLE, GetWindowLong(formhandle, GWL_EXSTYLE) Or WS_EX_LAYERED
SetLayeredWindowAttributes formhandle, vbCyan, 0&, LWA_COLORKEY
Me.BackColor = vbCyan
End Sub
Last edited by kazar; Apr 13th, 2006 at 06:40 AM .
KAZAR
The Law Of Programming:
As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
__________________________________
www.startingqbasic.co.uk
Apr 15th, 2006, 08:32 AM
#21
Addicted Member
Re: Making A Form Transparent (But with visible controls)
I want to see to the form background, not through that part of the form also
Resizing
System Balloons
If your question is answered, please mark the thread resolved by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button.
Remember to rate a post if you find it helpful
Apr 25th, 2006, 11:22 PM
#22
Re: Making A Form Transparent (But with visible controls)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width