启动程序时弹出一个动画然后动画消失再显示程序,不要用GIF之类的代替,要用VB编制,有没有好的代码啊,搜了半天也没找到

解决方案 »

  1.   

    从别人那儿学来的:要在form_unload时调用后面的窗口,所涉及的控件自己可以加,图片自己选。
    代码如下:直接就可以用。
    Private Type rBlendProps
        tBlendOp As Byte
        tBlendOptions As Byte
        tBlendAmount As Byte
        tAlphaType As Byte
    End TypePrivate Declare Function AlphaBlend Lib "msimg32" (ByVal hDestDC As Long, _
            ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _
            ByVal nHeight As Long, ByVal hSrcDC As Long, _
            ByVal xSrc As Long, ByVal ySrc As Long, ByVal WidthSrc As Long, _
            ByVal HeightSrc As Long, ByVal blendFunct As Long) As BooleanPrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
            (Destination As Any, Source As Any, ByVal Length As Long)Dim lTime As Byte'拷贝图片的描述部分
    'Requires Windows NT 4.0 or later; Requires Windows 95 or laterConst RC_PALETTE As Long = &H100
    Const SIZEPALETTE As Long = 104
    Const RASTERCAPS As Long = 38
    Private Type PALETTEENTRY
        peRed As Byte
        peGreen As Byte
        peBlue As Byte
        peFlags As Byte
    End Type
    Private Type LOGPALETTE
        palVersion As Integer
        palNumEntries As Integer
        palPalEntry(255) As PALETTEENTRY ' Enough for 256 colors
    End Type
    Private Type GUID
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(7) As Byte
    End Type
    Private Type PicBmp
        Size As Long
        Type As Long
        hBmp As Long
        hPal As Long
        Reserved As Long
    End Type
    Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
    Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal iCapabilitiy As Long) As Long
    Private Declare Function GetSystemPaletteEntries Lib "gdi32" (ByVal hdc As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long
    Private Declare Function CreatePalette Lib "gdi32" (lpLogPalette As LOGPALETTE) As Long
    Private Declare Function SelectPalette Lib "gdi32" (ByVal hdc As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As Long
    Private Declare Function RealizePalette Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function GetDC Lib "USER32" (ByVal hwnd As Long) As LongSub ShowTransparency(cSrc As PictureBox, cDest As PictureBox, ByVal nLevel As Byte)
        Dim LrProps As rBlendProps
        Dim LnBlendPtr As Long
        
        cDest.Cls
        LrProps.tBlendAmount = nLevel
        CopyMemory LnBlendPtr, LrProps, 4
        With cSrc
            AlphaBlend cDest.hdc, 0, 0, .ScaleWidth, .ScaleHeight, _
                .hdc, 0, 0, .ScaleWidth, .ScaleHeight, LnBlendPtr
        End With
        cDest.Refresh
    End SubPrivate Sub Command1_Click()
        lTime = 0
        Timer1.Interval = 70
        Timer1.Enabled = True
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        Frm_Logon.Show
    End SubPrivate Sub Timer1_Timer()
        lTime = lTime + 15      '可以控制渐变的速度
        ShowTransparency Picture2, Picture1, lTime
        If lTime >= 255 Then
            Timer1.Enabled = False
            lTime = 255
            Me.Caption = Str(Int(lTime / 2.55)) + "%"
            Unload Me
            Exit Sub
        End If
        Me.Caption = Str(Int(lTime / 2.55)) + "%"
    End SubFunction CreateBitmapPicture(ByVal hBmp As Long, ByVal hPal As Long) As Picture
        Dim R As Long, Pic As PicBmp, IPic As IPicture, IID_IDispatch As GUID    'Fill GUID info
        With IID_IDispatch
            .Data1 = &H20400
            .Data4(0) = &HC0
            .Data4(7) = &H46
        End With    'Fill picture info
        With Pic
            .Size = Len(Pic) ' Length of structure
            .Type = vbPicTypeBitmap ' Type of Picture (bitmap)
            .hBmp = hBmp ' Handle to bitmap
            .hPal = hPal ' Handle to palette (may be null)
        End With    'Create the picture
        R = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)    'Return the new picture
        Set CreateBitmapPicture = IPic
    End Function
    Function hDCToPicture(ByVal hDCSrc As Long, ByVal LeftSrc As Long, ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long) As Picture
        Dim hDCMemory As Long, hBmp As Long, hBmpPrev As Long, R As Long
        Dim hPal As Long, hPalPrev As Long, RasterCapsScrn As Long, HasPaletteScrn As Long
        Dim PaletteSizeScrn As Long, LogPal As LOGPALETTE    'Create a compatible device context
        hDCMemory = CreateCompatibleDC(hDCSrc)
        'Create a compatible bitmap
        hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
        'Select the compatible bitmap into our compatible device context
        hBmpPrev = SelectObject(hDCMemory, hBmp)    'Raster capabilities?
        RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS) ' Raster
        'Does our picture use a palette?
        HasPaletteScrn = RasterCapsScrn And RC_PALETTE ' Palette
        'What's the size of that palette?
        PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE) ' Size of    If HasPaletteScrn And (PaletteSizeScrn = 256) Then
            'Set the palette version
            LogPal.palVersion = &H300
            'Number of palette entries
            LogPal.palNumEntries = 256
            'Retrieve the system palette entries
            R = GetSystemPaletteEntries(hDCSrc, 0, 256, LogPal.palPalEntry(0))
            'Create the palette
            hPal = CreatePalette(LogPal)
            'Select the palette
            hPalPrev = SelectPalette(hDCMemory, hPal, 0)
            'Realize the palette
            R = RealizePalette(hDCMemory)
        End If    'Copy the source image to our compatible device context
        R = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, vbSrcCopy)    'Restore the old bitmap
        hBmp = SelectObject(hDCMemory, hBmpPrev)    If HasPaletteScrn And (PaletteSizeScrn = 256) Then
            'Select the palette
            hPal = SelectPalette(hDCMemory, hPalPrev, 0)
        End If    'Delete our memory DC
        R = DeleteDC(hDCMemory)    Set hDCToPicture = CreateBitmapPicture(hBmp, hPal)
    End Function
      

  2.   

    Private Sub Form_Load()Command1.Visible = False
    Frm_Transparency.Width = 533 * Screen.TwipsPerPixelY
    Frm_Transparency.Height = 400 * Screen.TwipsPerPixelX
    Frm_Transparency.Top = (Screen.Height - Frm_Transparency.Height) / 2
    Frm_Transparency.Left = (Screen.Width - Frm_Transparency.Width) / 2
    Me.Appearance = 0
    Picture1.Appearance = 0
    Picture2.Appearance = 0
    Picture1.BorderStyle = 0
    Picture2.BorderStyle = 0
    Picture2.Visible = FalsePicture1.ScaleMode = 3
    Picture2.ScaleMode = 3Me.AutoRedraw = True
    Picture1.AutoRedraw = True
    Picture2.AutoRedraw = True    Dim X, Y As Long
        
        'Picture1.Move 0, 0, Me.Width, Me.Height
        Picture1.Move 0, 0, 10 * Screen.TwipsPerPixelY, Me.Height
        Picture2.Move 0, 0, Me.Width, Me.Height
        
        X = (Screen.Width - Me.Width) / 2 / Screen.TwipsPerPixelX
        Y = (Screen.Height - Me.Height - 1) / 2 / Screen.TwipsPerPixelY
        
        '拷贝本窗体覆盖的图片到Picture2
        Set Picture2.Picture = hDCToPicture(GetDC(0), X, Y, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY)
        
        lTime = 0
        Timer2.Interval = 10
        Timer2.Enabled = True
        Timer1.Interval = 50
        Timer1.Enabled = False
    End SubPrivate Sub Timer2_Timer()
        If Picture1.Width < Frm_Transparency.Width Then
            Picture1.Width = Picture1.Width + 4 * Screen.TwipsPerPixelY
        Else
            Picture1.Width = Frm_Transparency.Width
            Timer2.Enabled = False
            Timer1.Interval = 50
            Timer1.Enabled = True
        End If
    End Sub