Option Explicit
'Add a slider control to the project (Slider1)
Private Declare Function SetParent Lib "user32" ( _
ByVal hWndChild As Long, _
ByVal hWndNewParent As Long _
) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
(ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _
ByVal lpProcName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule 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_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2
Public Sub AlphaBlendForm(ByVal lhWnd As Long, ByVal intTranslucenceLevel As Integer)
If APIExists("SetLayeredWindowAttributes", "User32") Then
SetWindowLong lhWnd, GWL_EXSTYLE, WS_EX_LAYERED
SetLayeredWindowAttributes lhWnd, 0, intTranslucenceLevel, LWA_ALPHA
Else
MsgBox "Your OS does not support Alpha Blending.", vbExclamation, "Alpha Blend"
End If
End Sub
Public Function APIExists(ByVal pstrFunctionName As String, ByVal pstrDllName As String) As Boolean
Dim lngHandle As Long
Dim lngAddr As Long
lngHandle = LoadLibrary(pstrDllName)
If Not (lngHandle = 0) Then
lngAddr = GetProcAddress(lngHandle, pstrFunctionName)
FreeLibrary lngHandle
End If
APIExists = Not (lngAddr = 0)
End Function
Private Sub Command1_Click()
Dim lhWnd As Long
'get handle to notepad
lhWnd = FindWindow(vbNullString, "Untitled - Notepad")
'if not open, launch Notepad
If lhWnd = 0 Then
Shell "notepad.exe"
lhWnd = FindWindow(vbNullString, "Untitled - Notepad")
End If
'make it a child
Call SetParent(lhWnd, Me.hwnd)
End Sub
Private Sub Form_Load()
AlphaBlendForm Me.hwnd, 190 'MAX VALUE = OPAIC/ MIN VALUE = 0 CANT SEE
End Sub
Private Sub Slider1_Scroll()
AlphaBlendForm Me.hwnd, Slider1.Value
End Sub