Membuat SystemMatrics pada sebuah Program Aplikasi di VB6

Membuat SystemMatrics pada sebuah Program Aplikasi di VB6 - Pernahkan Anda melihat sebuah program yang memunculkan Update terbaru dari sebuah program, dimana program ini muncul di sebelah sudut kanan bawah monitor yang artinya program itu meminta update versi terbarunya .Contoh dari program ini adalah misalnya AntiVirus, Browser dll. System Matrix adalah suatu fungsi yang dapat mengambil informasi tetntang suatu system yang di tampilkan di jendela tertentu.

Baiklan sekarang kita menuju ke tutorial bagaimana cara membuat aplikasi tersebut perhatikan langkah berikut dibawah ini:

Membuat SystemMatrics pada sebuah Program Aplikasi di VB6

1. Buka Form VB Anda sebanyak 2 Form yaitu Form1 dan Form2
2. Sekarang buka Form1, tambahkan 2 Timer, 2 CommandButton dan beberapa Lebel (optional) Atur Propertes masing-masing:
  • Timer1                         Name     : tmrNotify
  • Timer2                         Name     : tmrSemiTransparent 
  • Command1                  Name     : cmdOK                      Caption  : OK
  • Command2                 Name      : cmdCancel                Caption  : Cancel
  • Label1 Captionnya   terserah Anda

3 Desainlah seperti gambar dibawah ini :
Desain Form1
4. Untuk Form2 desainnya terserah Anda karena form2 hanya berfungsi menampilkan saja untuk membuktikan form tersebut bekerja atau tidak.

5. Buka kembali Form1 kemudian buka jendela kode pada Form1 dan ketik kode dibawah ini :

Option Explicit

Dim blnHighlighted As Boolean
Dim blnMouseDownClick As Boolean 'bug fixed on flickering

Private Type POINTAPI
    x As Long
    y As Long
End Type

Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Sub InitCommonControls Lib "COMCTL32.DLL" ()

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" (ByVal hWnd As Long, ByVal color As Long, ByVal x As Byte, ByVal alpha As Long) As Boolean

Const LWA_BOTH = 3
Const LWA_ALPHA = 2
Const LWA_COLORKEY = 1
Const GWL_EXSTYLE = -20
Const WS_EX_LAYERED = &H80000

Dim iTransparant As Integer
Dim blnUp As Boolean

Private Sub Form_Initialize()
    InitCommonControls
End Sub

Private Sub MakeTransparan(hWndBro As Long, iTransp As Integer)
   On Error Resume Next
  
   Dim ret As Long
   ret = GetWindowLong(hWndBro, GWL_EXSTYLE)
  
   SetWindowLong hWndBro, GWL_EXSTYLE, ret Or WS_EX_LAYERED
   SetLayeredWindowAttributes hWndBro, RGB(255, 255, 0), iTransp, LWA_ALPHA
   Exit Sub

End Sub

Private Sub cmdOK_Click()
    'Kode selanjutnya disini ....
    Form2.Show   'form yang akan anda tampilkan
    Unload Me
   
    blnUp = True
    tmrNotify.Enabled = True
End Sub

Private Sub cmdCancel_Click()
    'kode selanjutnya disini ....

    blnUp = False
    tmrNotify.Enabled = True
End Sub

Private Sub Form_Load()
tmrNotify.Interval = 1
tmrSemiTransparent.Interval = 1

    MakeTransparan Me.hWnd, 100
    Top = ((GetSystemMetrics(17) + GetSystemMetrics(4)) * Screen.TwipsPerPixelY)
    Left = (GetSystemMetrics(16) * Screen.TwipsPerPixelX) - Width
    blnUp = True
End Sub

Private Sub Form_MouseDown(Button As Integer, shift As Integer, x As Single, y As Single)
    blnMouseDownClick = True
End Sub

Private Sub Form_MouseMove(Button As Integer, shift As Integer, x As Single, y As Single)
    If blnHighlighted Then Exit Sub
    blnHighlighted = True
    tmrSemiTransparent.Enabled = True
    MakeTransparan Me.hWnd, 255
End Sub

Private Sub Form_MouseUp(Button As Integer, shift As Integer, x As Single, y As Single)
    blnMouseDownClick = False
End Sub

Private Sub tmrSemiTransparent_Timer()
    If blnMouseDownClick Then Exit Sub
    Dim pt As POINTAPI
    GetCursorPos pt
    ScreenToClient hWnd, pt
    If (pt.x < 0 Or pt.y < 0) Or _
    (pt.x > (Me.ScaleLeft + Me.ScaleWidth) / Screen.TwipsPerPixelX) Or _
       (pt.y > (Me.ScaleTop + Me.ScaleHeight) / Screen.TwipsPerPixelY) Then
        blnHighlighted = False
        tmrSemiTransparent.Enabled = False
        MakeTransparan Me.hWnd, 100
    End If
End Sub

Private Sub tmrNotify_Timer()
    Const s = 100
    Dim v As Single
    v = (GetSystemMetrics(17) + GetSystemMetrics(4)) * Screen.TwipsPerPixelY
    If blnUp = True Then
        If Top - s <= v - Height Then
            Top = Top - (Top - (v - Height))
            tmrNotify.Enabled = False
        Else
            Top = Top - s
        End If
    Else
        Top = Top + s
        If Top >= v Then End
    End If
End Sub

5. Simpan Kode Anda dan jalankan Program.

Cara Kerja:
Ketika Anda belum mengarahkan mouse ke atas aplikasi tersebut pada program yang muncul maka form akan transfarant seperti gambar diatas dan begitupun sebaliknya.
Ketika Anda mengklik tombol OK maka form yang lain akan muncul dan ketika Anda mengklik Cancel maka form akan Logout

Demikian tip cara Membuat SystemMatrics pada sebuah Program Aplikasi di VB6. Selamat mencoba semoga berhasil.

No comments: