Saturday, January 13, 2007

Making any Window Transparent on XP

Intro
This little piece of code written in VB6 allows you to make any window transparent.
Make Firefox, Opera, Internet Explorer, Windows Media Player, Google Talk, Yahoo Messenger, Windows Explorer, basically any window, transparent on Windows XP.

*Transparent Opera

Download
+Zipped binary for Windows XP from here Transp.ZIP [5 KB]
+Source code from planet-source-code

Usage


  • Run the Program

  • Place the mouse over the title bar of the window which you want to make transparent.

  • Now leaving the mouse in the title bar, press the Ctrl button (Normally on the lower right side of the keyboard), now you can see the window name shown in the software.

  • Now press the "Set Transparent" Button

  • Adjust the Transparency Slider to the required transparency. (Dont set below 100 you will loose sight of the window)

  • Press the "Set Opaque" Button to make the window opaque again

  • To do for another window repeat the same steps.



Source

Const GWL_EXSTYLE = -20
Const WS_EX_LAYERED = &H80000
Const GWL_STYLE = (-16)
Const WS_VISIBLE = &H10000000
Const LWA_ALPHA = &H2

Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Option Explicit

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 Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long


'@ http://digitalpbk.blogspot.com/2007/01/making-any-window-transparent-on-xp.html


Private Type POINTAPI
x As Long
y As Long
End Type

Public xhwnd As Long

Private Sub Command1_Click()
SetWindowLong xhwnd, GWL_EXSTYLE, WS_EX_LAYERED
SetLayeredWindowAttributes xhwnd, 0, Slider1.Value, LWA_ALPHA
End Sub

Private Sub Command2_Click()
SetWindowLong xhwnd, GWL_EXSTYLE, 0
End Sub


Private Sub Label2_Click()
ShellExecute Me.hwnd, "", "http://digitalpbk.blogspot.com/2007/01/making-any-window-transparent-on-xp.html?ref=EXE", "", "", 1
End Sub

Private Sub Slider1_Change()
SetLayeredWindowAttributes xhwnd, 0, Slider1.Value, LWA_ALPHA 'Change the transparency level
End Sub

Private Sub Timer1_Timer()
Dim xy As POINTAPI
Dim retStr As String * 80

If GetAsyncKeyState(vbKeyControl) Then
Call GetCursorPos&(xy)
xhwnd = WindowFromPoint(xy.x, xy.y)
Call GetWindowText(xhwnd, retStr, 100)
If xhwnd = Me.hwnd Then 'Protect self from being transparent
Label1.Caption = "Making me transparent is not good!"
xhwnd = 0
Else
Label1.Caption = retStr & " " & xy.x & " " & xy.y & " " & xhwnd
End If
End If
End Sub

Anything else?
Lemme know ...leave a comment.

12 comments:

Anonymous said...

nice application..
visually appealing one
i wonder where arun gets these codes from:D

sedat said...

google for "PowerMenu" don't waste your time for such code.

Anonymous said...

sedat, what do you mean 'dont waste your time for such code' do you even understand it? it's a code. incase you don't know how to read it, it's a good one.

@sherin, reading windows api will help ;) lots of samples around the net of course.

-Mac

Anonymous said...

Awesome. Love it!

Anonymous said...

any idea if this has been ported to vista yet :P

Arun Prabhakar said...

Vista ? Yuck!

Anonymous said...

Like all other transparency utils this does not work on console windows. :-(

Anonymous said...

cute little code. very nice indeed. although this code necessitates doing it for each and every window you want transparent, it's blazing fast when compared to other transparency utilities like
1. actual transparency
2. alphaxp
3. true transparency (pathetically slow - don't try it!)

i wonder if a general transparency fx like that in vista could be done. thanx.

Anonymous said...

Is there a way you can set it so that a folder remembers it's transparency setting?

Basically I'm after a way to concolidate all my desktop icons into one, and idealy on a mouse over have it display all desktop icons untill either an icon is selected or the mouse clicks a blank area. Any suggestions?

So far putting it all into one folder with a transparency is a cowboy solution. :S

Anonymous said...

Very nice, just what I was looking for. Much easier to use and less bloated than "other" pieces of software.

Thanks a million!

Anonymous said...

Cool Application... and so easy to use :D

Sanjay said...

Hi Arun plz can u upload the application again cannot download.