Imploze a exploze oken

Postup:
Do modulu vložte následující deklarace:


'Struktura pro API Funkce
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type


'Deklarace API funkcí
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

V modulu založte novou funkci ExplodeForm:

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

Založte další funkci ImplodeForm:

Public Sub ImplodeForm(f As Form, Direction As Integer, Movement As Integer, ModalState 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

Na událost Load fromuláře vložte tento kód:

Private Sub Form_Load()

      Call ExplodeForm(Me, 500)

End Sub

Na událost QueryUnload vložte tento kód:

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

      Call ImplodeForm(Me, 2, 500, 1)

End Sub

Spusťte aplikaci a uvidíte ...

Zpět

Autor: The Bozena