Add Vista Effects in your Forms (From VB HowTos)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ali Rizwan
    Banned
    Contributor
    • Aug 2007
    • 931

    #1

    Add Vista Effects in your Forms (From VB HowTos)

    Hi all,

    Use following functions to add vista effects to your forms.

    Add a module and write following code >>>

    [CODE=vb]Public Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA " _
    (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Public Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA " _
    (ByVal hWnd As Long, ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long
    Public Const GWL_STYLE = (-16)
    Public Const GWL_EXSTYLE = (-20)
    Public Declare Function SetLayeredWindo wAttributes Lib "User32" _
    (ByVal hWnd As Long, ByVal crKey As Long, _
    ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
    Public Const LWA_COLORKEY = &H1
    Public Const LWA_ALPHA = &H2
    Public Const WS_EX_LAYERED = &H80000

    Public Declare Function SendMessageLong Lib "User32" Alias "SendMessag eA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Declare Function ReleaseCapture Lib "User32" () As Long
    Public Const WM_SYSCOMMAND1 = &H112&
    Public Const SC_MOVE1 = &HF010&
    Public Const WM_NCLBUTTONDOW N1 = &HA1
    Public Const HTCAPTION1 = 2

    Public m_lAlpha As Long

    Public lStyle As Long
    Public lAlpha

    Private Enum EffectCosnt
    ecEffectIn = 1
    ecEffectOut = 2
    End Enum

    Public Sub fade()

    m_lAlpha = 255

    If (m_lAlpha = 255) Then

    lStyle = GetWindowLong(S PL.hWnd, GWL_EXSTYLE)
    lStyle = lStyle Or WS_EX_LAYERED
    SetWindowLong SPL.hWnd, GWL_EXSTYLE, lStyle
    End If

    m_lAlpha = m_lAlpha - 255
    lAlpha = m_lAlpha
    SetLayeredWindo wAttributes SPL.hWnd, 0, lAlpha, LWA_ALPHA

    End Sub

    Private Sub VistaExplodeEff ect(ByRef frm As Form, Optional ByVal Effect As EffectCosnt = ecEffectIn, Optional ByVal BounceIn As Boolean = True, Optional ByVal BounceOut As Boolean = True)
    Const STEPS As Long = 255

    Dim X As Long
    Dim Y As Long
    Dim lngFormWidth As Long
    Dim lngFormHeight As Long
    Dim blnFullWidth As Boolean
    Dim blnFullHeight As Boolean


    With frm
    If .WindowState = vbMaximized Then
    .WindowState = vbNormal
    .Width = Screen.Width
    .Height = Screen.Height
    End If


    lngFormWidth = .Width
    lngFormHeight = .Height


    If Effect = ecEffectIn Then
    X = 0
    Y = 0

    .Width = 0
    .Height = 0
    .Show
    DoEvents

    blnFullWidth = False
    blnFullHeight = False
    Do While Not (blnFullWidth And blnFullHeight)
    .Move (Screen.Width - .Width) / 2, (Screen.Height - .Height) / 2, X, Y
    DoEvents

    If X <= lngFormWidth Then X = X + STEPS Else blnFullWidth = True
    If Y <= lngFormHeight Then Y = Y + STEPS Else blnFullHeight = True


    If (m_lAlpha = 0) Then

    lStyle = GetWindowLong(. hWnd, GWL_EXSTYLE)
    lStyle = lStyle Or WS_EX_LAYERED
    SetWindowLong .hWnd, GWL_EXSTYLE, lStyle
    End If

    m_lAlpha = m_lAlpha + 15
    lAlpha = m_lAlpha
    If (lAlpha > 255) Then
    lAlpha = 255
    End If

    SetLayeredWindo wAttributes .hWnd, 234, lAlpha, LWA_ALPHA
    If (m_lAlpha > 234) Then
    m_lAlpha = 234
    End If


    Loop


    If BounceIn Then
    .Move (Screen.Width - .Width) / 2, (Screen.Height - .Height) / 2, lngFormWidth, lngFormHeight
    DoEvents
    End If
    Else
    X = lngFormWidth
    Y = lngFormHeight

    If BounceOut Then
    .Move (Screen.Width - .Width) / 2, (Screen.Height - .Height) / 2, X + (STEPS * 2), Y + (STEPS * 2)

    DoEvents
    End If

    blnFullWidth = False
    blnFullHeight = False
    Do While Not (blnFullWidth And blnFullHeight)
    .Move (Screen.Width - .Width) / 2, (Screen.Height - .Height) / 2, X, Y
    DoEvents

    If X <= lngFormWidth Then
    X = X - STEPS
    If X < 0 Then
    X = 0
    blnFullWidth = True
    End If
    End If

    If Y <= lngFormHeight Then
    Y = Y - STEPS
    If Y < 0 Then
    Y = 0
    blnFullHeight = True
    End If
    End If


    If (m_lAlpha = 255) Then

    lStyle = GetWindowLong(. hWnd, GWL_EXSTYLE)
    lStyle = lStyle Or WS_EX_LAYERED
    SetWindowLong .hWnd, GWL_EXSTYLE, lStyle
    End If

    m_lAlpha = m_lAlpha - 5
    lAlpha = m_lAlpha
    If (lAlpha < 0) Then
    lAlpha = 0
    End If
    SetLayeredWindo wAttributes .hWnd, 0, lAlpha, LWA_ALPHA
    If (m_lAlpha < 0) Then
    m_lAlpha = 0
    End If

    Loop

    .Hide
    DoEvents
    End If
    End With
    End Sub

    [/CODE]

    Now add following code in form code.

    [CODE=vb]Private Sub Form_Initialize ()

    fade
    VistaExplodeEff ect Me

    End Sub[/CODE]

    Note : Fade function is used to set 100% transperency to form. You can also embed it in effect function by using if else statement.

    Regards
    >> ALI <<
    Last edited by debasisdas; Apr 14 '08, 05:35 AM. Reason: added code=vb tags
Working...