Problem Computer And Software

VB 6 Zone

|
Module From Transparan VB6 Dan Enable / Disable Nya




MODULE TRANSPARENT
  • Caranya :
  1. Buka VB6
  2. Buat Project Baru
  3. Buat Module Baru
  4. Lalu Copy Code Module Ini :

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 UpdateLayeredWindow Lib "user32" (ByVal hWnd As Long, ByVal hDCDst As Lon...g, pptDst As Any, psize As Any, ByVal hDCSrc As Long, pptSrc As Any, crKey As Long, ByVal pblend As Long, ByVal dwFlags As Long) 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 Const GWL_EXSTYLE = (-20)
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const ULW_COLORKEY = &H1
Private Const ULW_ALPHA = &H2
Private Const ULW_OPAQUE = &H4
Private Const WS_EX_LAYERED = &H80000

Public Function isTransparent(ByVal hWnd As Long) As Boolean
On Error Resume Next
Dim msg As Long
msg = GetWindowLong(hWnd, GWL_EXSTYLE)
If (msg And WS_EX_LAYERED) = WS_EX_LAYERED Then
isTransparent = True
Else
isTransparent = False
End If
If Err Then
isTransparent = False
End If
End Function

Public Function MakeTransparent(ByVal hWnd As Long, Perc As Integer) As Long
Dim msg As Long
On Error Resume Next
If Perc < 0 Or Perc > 255 Then
MakeTransparent = 1
Else
msg = GetWindowLong(hWnd, GWL_EXSTYLE)
msg = msg Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, msg
SetLayeredWindowAttributes hWnd, 0, Perc, LWA_ALPHA
MakeTransparent = 0
End If
If Err Then
MakeTransparent = 2
End If
End Function

Public Function MakeOpaque(ByVal hWnd As Long) As Long
Dim msg As Long
On Error Resume Next
msg = GetWindowLong(hWnd, GWL_EXSTYLE)
msg = msg And Not WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, msg
SetLayeredWindowAttributes hWnd, 0, 0, LWA_ALPHA
MakeOpaque = 0
If Err Then
MakeOpaque = 2
End If
End Function


Penerapan

  • Cara Menerapkan Pada Form :
  1. Buat Form Baru
  2. Lalu Masukan Code Berikut :

Private Sub Form_Load()
MakeTransparent Me.hWnd, ( Atur Sesuka Anda "0 Hilang Semua, 255 Normal "Jangan Pake Kurung )
End Sub

  • Contoh

Private Sub Form_Load()
MakeTransparent Me.hWnd, 230
End Sub


Enable Dan Disable Form Transparent
  • Conoth Enable Disable Transparent By Button
  1. Di Form Buat 2 Button
  2. Button Satu Isikan Code Berikut
  • Private Sub Button1_Click()
MakeTransparent Me.hWnd, 170
End Sub

3. Button Dua Isikan Code Berikut
  • Private Sub Button2_Click()
MakeTransparent Me.hWnd, 255
End Sub

Setelah itu Coba Jalankan Dan Click Kedua Button Itu.... Lihat Perbedaan nya...

Cari Sesuatu?