Results 1 to 8 of 8

Thread: Animation demonstration drawing a rectangle with gradient filling by vb6

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,180

    Animation demonstration drawing a rectangle with gradient filling by vb6

    from here?https://blog.csdn.net/weixin_3210910...ails/117191984
    This may be the original link that I can't open to view.
    http://vbcity.com/forums/t/73200.aspx

    Code:
      Dim r As RECT
    
        r.Left = 10
        r.Top = 10
        r.Right = 300
        r.Bottom = 550
        Call gdiDrawGradient(Me.hdc, r, vbRed, vbBlue, True)
    Name:  demo.gif
Views: 355
Size:  43.1 KB
    Code:
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Declare Function timeGetTime Lib "winmm.dll" () As Long
    Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
    Declare Function timeEndPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
    Public PauseTime As Long
    
    
    Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    
    Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
    Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
    Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    
    
    
    Function Pause(HowLong As Long)
        Dim tick As Long
        tick = timeGetTime()
        Do
           DoEvents
          Sleep 1
        Loop Until tick + HowLong < timeGetTime
    End Function
    
    Public Sub gdiDrawGradient( _
                ByVal hdc As Long, _
                ByRef rct As RECT, _
                ByVal lEndColor As Long, _
                ByVal lStartColor As Long, _
                ByVal bVertical As Boolean)
    
        Dim lStep As Long
        Dim lPos As Long, lSize As Long
        Dim bRGB(1 To 3) As Integer
        Dim bRGBStart(1 To 3) As Integer
        Dim dR(1 To 3) As Double
        Dim dPos As Double, d As Double
        Dim hBr As Long
        Dim tR As RECT
    
        LSet tR = rct
        If bVertical Then
            lSize = (tR.Bottom - tR.Top)
        Else
            lSize = (tR.Right - tR.Left)
        End If
        lStep = lSize \ 255
        If (lStep < 3) Then
            lStep = 3
        End If
    
        bRGB(1) = lStartColor And &HFF&
        bRGB(2) = (lStartColor And &HFF00&) \ &H100&
        bRGB(3) = (lStartColor And &HFF0000) \ &H10000
        bRGBStart(1) = bRGB(1): bRGBStart(2) = bRGB(2): bRGBStart(3) = bRGB(3)
        dR(1) = (lEndColor And &HFF&) - bRGB(1)
        dR(2) = ((lEndColor And &HFF00&) \ &H100&) - bRGB(2)
        dR(3) = ((lEndColor And &HFF0000) \ &H10000) - bRGB(3)
    
        For lPos = lSize To 0 Step -lStep '
            ' Draw bar
            If bVertical Then
                tR.Top = tR.Bottom - lStep
            Else
                tR.Left = tR.Right - lStep
            End If
            If tR.Top < rct.Top Then
                tR.Top = rct.Top
            End If
            If tR.Left < rct.Left Then
                tR.Left = rct.Left
            End If
    
            hBr = CreateSolidBrush((bRGB(3) * &H10000 + bRGB(2) * &H100& + bRGB(1)))
            FillRect hdc, tR, hBr
            DeleteObject hBr
    
            ' Adjust colour '
            dPos = ((lSize - lPos) / lSize)
            If bVertical Then
                tR.Bottom = tR.Top
                bRGB(1) = bRGBStart(1) + dR(1) * dPos
                bRGB(2) = bRGBStart(2) + dR(2) * dPos
                bRGB(3) = bRGBStart(3) + dR(3) * dPos
            Else
                tR.Right = tR.Left
                bRGB(1) = bRGBStart(1) + dR(1) * dPos
                bRGB(2) = bRGBStart(2) + dR(2) * dPos
                bRGB(3) = bRGBStart(3) + dR(3) * dPos
            End If
                If PauseTime > 0 Then Pause PauseTime
        Next lPos
    
    End Sub
    Attached Files Attached Files
    Last edited by xiaoyao; Jul 13th, 2024 at 05:36 PM.

  2. #2
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,356

    Re: Animation demonstration drawing a rectangle with gradient filling by vb6

    If you repost the code of others, could you at least give them credit -
    or include the link to the original: http://vbcity.com/forums/t/73200.aspx

    Olaf

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,180

    Re: Animation demonstration drawing a rectangle with gradient filling by vb6

    https://blog.csdn.net/weixin_3210910...ails/117191984
    From here. I don't know which website the other website came from.
    99% of my source code comes from some websites in China. I have sent a lot of them before, but you can't read Chinese.
    Many communities in foreign countries, as well as the Google website, can not be opened.
    For this vbforums community website, it takes 10 to 40 seconds to open each time, which is very slow.
    Last edited by xiaoyao; Jul 13th, 2024 at 05:34 PM.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,327

    Re: Animation demonstration drawing a rectangle with gradient filling by vb6

    Well, that appears to have been cleaned up. A post to the original, once found, was added.
    My usual boring signature: Nothing

  5. #5
    Lively Member
    Join Date
    Aug 2020
    Location
    Victoria Texas 77904
    Posts
    91

    Re: Animation demonstration drawing a rectangle with gradient filling by vb6

    This is nice, Would you be able to do it with three colors ?

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,180

    Re: Animation demonstration drawing a rectangle with gradient filling by vb6

    Quote Originally Posted by KFrosty View Post
    This is nice, Would you be able to do it with three colors ?
    This should be very simple. If a ring is filled with different colors, this dynamic effect will be better, but now this code is only the foundation, and you need to learn a lot of image programming API to realize it.

  7. #7
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,141

    Re: Animation demonstration drawing a rectangle with gradient filling by vb6

    Quote Originally Posted by KFrosty View Post
    This is nice, Would you be able to do it with three colors ?
    For the first half use color A -> B
    Then for the second half use color B -> C

  8. #8
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,409

    Re: Animation demonstration drawing a rectangle with gradient filling by vb6

    Quote Originally Posted by KFrosty View Post
    This is nice, Would you be able to do it with three colors ?
    Actually the code is completely redundant. There is GdipCreateLineBrushFromRect API already in GDI+ which does everything this does without awkward loops.

    cheers,
    </wqw>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width