Cara Membuat Efek Kejut Pada Sebuah Form di VB6

Pada artikel kali ini saya akan berbagi kode unik di VB6 yaitu cara menampilkan sebuah Form degan efek kejut di vb6 dimana muncul saat beralih dari Form1 ke Form2. Ketika Form1 di load dilayar kemudan kita akan berpindah ke Form2 dengan mengklik sebuah commandbutton, maka sebelum muncul Form2 akan ada efek kejut berupa background hitam muncul sekilas dalam hitungan sekian detik kemudian menghilang hingga muncul Form2.

Bagi Anda yang penasaran bagaiamana cara membuat efek ini, berikut adalah langkah-langkahnya :

  1. Buka Form VB6 dengan Standar EXE
  2. Pada Form1 tambahkan 1 Commandbutton 
  3. Lalu tambahkan satu buah Form lagi yaitu Form2
  4. Kemudian tambahkan 1 buah Module dengan cara klik Project >> Add Module
  5. Setelah menambahkan Module, copykan kode dibawah ini di jendela Module :


Option Explicit

Type RECT

  Left As Long

  Top As Long

  Right As Long

  Bottom As Long

End Type

 

Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long

Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long

Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long

Declare Function SelectObject Lib "user32" (ByVal hdc As Long, ByVal hObject As Long) As Long

Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

 

Public Const IMPLODE_EXPLODE_VALUE = 1500   'you can change the value

 

Sub ExplodeForm(f As Form, Movement As Integer)

    Dim myRect As RECT

    Dim formWidth%, formHeight%, i%, X%, Y%, Cx%, Cy%

    Dim TheScreen As Long

  Dim Brush As Long

  GetWindowRect f.hwnd, myRect

    formWidth = (myRect.Right - myRect.Left)

    formHeight = myRect.Bottom - myRect.Top

      TheScreen = GetDC(0)

    Brush = CreateSolidBrush(f.BackColor)

    For i = 1 To Movement

        Cx = formWidth * (i / Movement)

        Cy = formHeight * (i / Movement)

        X = myRect.Left + (formWidth - Cx) / 2

        Y = myRect.Top + (formHeight - Cy) / 2

        Rectangle TheScreen, X, Y, X + Cx, Y + Cy

    Next i

  X = ReleaseDC(0, TheScreen)

    DeleteObject (Brush)

End Sub

 

Public Sub ImplodeForm(f As Form, Movement As Integer)

    Dim myRect As RECT

    Dim formWidth%, formHeight%, i%, X%, Y%, Cx%, Cy%

    Dim TheScreen As Long

    Dim Brush As Long

    GetWindowRect f.hwnd, myRect

    formWidth = (myRect.Right - myRect.Left)

    formHeight = myRect.Bottom - myRect.Top

    TheScreen = GetDC(0)

    Brush = CreateSolidBrush(f.BackColor)

    For i = Movement To 1 Step -1

        Cx = formWidth * (i / Movement)

        Cy = formHeight * (i / Movement)

        X = myRect.Left + (formWidth - Cx) / 2

        Y = myRect.Top + (formHeight - Cy) / 2

        Rectangle TheScreen, X, Y, X + Cx, Y + Cy

    Next i

    X = ReleaseDC(0, TheScreen)

    DeleteObject (Brush)

End Sub

6. Kemudian kembali ke Form1 pada Commandbutton Form1, ketik kode dibawah ini :

Private Sub Command1_Click()

Call ImplodeForm(Me, IMPLODE_EXPLODE_VALUE)
Unload Me
    Form2.Show 'form yang akan muncul sesudah efek kejut
    Set Form1 = Nothing

End Sub

Private Sub Form_Load()

Call ExplodeForm(Me, IMPLODE_EXPLODE_VALUE)

End Sub

Setelah kode diatas di buat coba jalankan Project Anda, kemudian tekan command1 untuk menampilkan form2. Perhatikan secara seksama!!! sebelum Form2 muncul

No comments: