Have you ever wanted to make an application (such as NotePad) transparent? ;-)
I was working on a couple of projects and stumbled across this...
In one project, I was interfacing with NotePad, Grabing and setting text...
In the other I was making my application simi-transparent so you could see the application behind it that it was interfacing with...
I noticed both of the sets of API calls were dealing with hWnd's...
So I decided to see what would happen if you put the functions together ;-)
(In case you haven't noticed in any of my other post... NotePad is my usual Guinea Pig in any given general API Test)
Here is the Code Required to Make Notepad transparent...
And this is an example of how to use it...
This will set the transparency of the last active window in the specified class that you clicked on...
So if you have 5 NotePad windows open, Click one and press the button to make it transparent...
This should work for any application, if you have the class name of the app...
For Example:
Use these for the Windows Calculator
SetTransparent "SciCalc", 192
SetNormal "SciCalc"
Use these for the Visual Basic Editor ;-)
SetTransparent "wndclass_desked_gsk", 192
SetNormal "wndclass_desked_gsk"
If you have VC++ and/or Visual Studio (ver 5 or 6) you can use Spy++ to get the names of other Window classes to use this on...
Have Fun ;-)
-and-
M E R R Y C H R I S T M A S
Have Fun, Be Young... Code BASIC
-Josh
PROGRAMMER:
Red-eyed, mumbling mammal capable of conversing with inanimate objects.
I was working on a couple of projects and stumbled across this...
In one project, I was interfacing with NotePad, Grabing and setting text...
In the other I was making my application simi-transparent so you could see the application behind it that it was interfacing with...
I noticed both of the sets of API calls were dealing with hWnd's...
So I decided to see what would happen if you put the functions together ;-)
(In case you haven't noticed in any of my other post... NotePad is my usual Guinea Pig in any given general API Test)
Here is the Code Required to Make Notepad transparent...
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal wClass As String, ByVal wName 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.dll" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Const LWA_ALPHA = &H2&
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
Sub SetTransparent(TargetClass As String, Opacity As Byte)
Dim TargetApp As Long, dwExStyle As Long
TargetApp = FindWindow(TargetClass, vbNullString)
dwExStyle = GetWindowLong(TargetApp, GWL_EXSTYLE) Or WS_EX_LAYERED
SetWindowLong TargetApp, GWL_EXSTYLE, dwExStyle
SetLayeredWindowAttributes TargetApp, 0, Opacity, LWA_ALPHA
End Sub
Sub SetNormal(TargetClass As String)
Dim TargetApp As Long, dwExStyle As Long
TargetApp = FindWindow(TargetClass, vbNullString)
SetLayeredWindowAttributes TargetApp, 0, 255, LWA_ALPHA
dwExStyle = GetWindowLong(TargetApp, GWL_EXSTYLE) Xor WS_EX_LAYERED
SetWindowLong TargetApp, GWL_EXSTYLE, dwExStyle
End Sub
And this is an example of how to use it...
Code:
[b] Private Sub Command1_Click()
SetTransparent "NotePad", 192
End Sub
Private Sub Command2_Click()
SetNormal "NotePad"
End Sub[/b]
This will set the transparency of the last active window in the specified class that you clicked on...
So if you have 5 NotePad windows open, Click one and press the button to make it transparent...
Code:
Note: Opacity is a byte value of 0 to 255...
0 is invisible, 255 is 100% opaque
63 is 25% visible
127 is 50% visible
191 is 75% visible
This should work for any application, if you have the class name of the app...
For Example:
Use these for the Windows Calculator
SetTransparent "SciCalc", 192
SetNormal "SciCalc"
Use these for the Visual Basic Editor ;-)
SetTransparent "wndclass_desked_gsk", 192
SetNormal "wndclass_desked_gsk"
If you have VC++ and/or Visual Studio (ver 5 or 6) you can use Spy++ to get the names of other Window classes to use this on...
Have Fun ;-)
-and-
M E R R Y C H R I S T M A S
Have Fun, Be Young... Code BASIC
-Josh

PROGRAMMER: