Wednesday, October 21, 2009

How to make transparent taskbar with VB6

Well,Here is the code to make transparent taskbar.. I have modify the code,so this code will also tell you how to save and read a text document file to your program..


Copy this code to module:
Public Declare Function GetClassName Lib _
    "user32.dll" Alias "GetClassNameA" _
    (ByVal hwnd As Long, ByVal lpClassName _
    As String, ByVal nMaxCount As Long) _
    As Long
Public Declare Function FindWindow Lib _
    "user32.dll" Alias "FindWindowA" _
    (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
Public Declare Function SetLayeredWindowAttributes _
    Lib "user32.dll" (ByVal hwnd As Long, _
    ByVal crKey As Long, ByVal bAlpha As Byte, _
    ByVal dwFlags As Long) As Long
Public Declare Function GetWindow Lib "user32" _
    (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetCursorPos Lib "user32" _
    (lpPoint As POINTAPI) As Long

Private Declare Function GetWindowLong Lib _
    "user32.dll" Alias "GetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As _
    Long) As Long
Private Declare Function SetWindowLong Lib _
    "user32.dll" Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long

Public Type POINTAPI
    X As Long
    Y As Long
End Type

Private Const GWL_EXSTYLE As Long = -20
Private Const WS_EX_LAYERED As Long = &H80000
Private Const LWA_ALPHA As Long = &H2

Private Type RECT
    Left As Long
    Top
As Long
    Right As Long
    Bottom As Long
End Type

Private Type WINDOWPLACEMENT
    Length As Long
    flags
As Long
    showCmd As Long
    ptMinPosition As POINTAPI
    ptMaxPosition As POINTAPI
    rcNormalPosition As RECT
End Type

Public Const GW_NEXT = 2
Public Const GW_CHILD = 5

Function Taskbar(persen As Integer)
    Dim Sebelumnya
As Long
    Dim hwnd As Long
   
    If persen > 100 Then persen = 100
    hwnd = FindWindow("Shell_TrayWnd", vbNullString)
    If (hwnd <> 0) Then
        Sebelumnya = GetWindowLong(hwnd, _
        GWL_EXSTYLE) Or WS_EX_LAYERED
        SetWindowLong hwnd, GWL_EXSTYLE, Sebelumnya
        SetLayeredWindowAttributes hwnd, _
        0, 255 * (persen / 100), LWA_ALPHA
    End If
    hwnd = FindWindow("BaseBar", vbNullString)
    If (hwnd <> 0) Then
        Sebelumnya = GetWindowLong(hwnd, _
        GWL_EXSTYLE) Or WS_EX_LAYERED
        SetWindowLong hwnd, GWL_EXSTYLE, Sebelumnya
        SetLayeredWindowAttributes hwnd, 0, 255 * _
        (persen / 100), LWA_ALPHA
    End If
End Function
Save the module as module1

And copy this code to form:

Private Sub Command1_Click()
Dim FNum
Dim transparant
FNum = FreeFile
transparant = "D:\" & ("\Log.txt")
Open transparant For Output As #1
Print #FNum, Text1.Text
Close #FNum
Unload Me
End Sub

Private Sub Form_Load()
Dim A As String
Dim transparant
transparant = "D:\" & ("\Log.txt")
On Error GoTo error
Open transparant For Input As #1
Do Until EOF(1)
Input #1, A$
Text1.Text = A$
Loop
Close 1
error:
End Sub

Private Sub HScroll1_Change()
Text1.Text = HScroll1.Value
End Sub

Private Sub HScroll1_Scroll()
Text1.Text = HScroll1.Value
End Sub

Private Sub Text1_Change()
HScroll1.Value = Text1.Text
Taskbar (Val(Text1.Text))
End Sub

Done.. Set ur taskbar tranparency now.. =)

No comments:

Post a Comment