Results 1 to 2 of 2

Thread: A shorter gradient code

  1. #1

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Question A shorter gradient code

    Anyone have a really short working gradient example. to smoothly run one color into the next? The ones ive currently seen or used are way to big.

    Open to suggestion...........

  2. #2

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    No worries, i found an old code merri posted to help me with. However if you have a shorter faster loading code, please post!

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type TRIVERTEX
    4.     x As Long
    5.     y As Long
    6.     Red As Integer
    7.     Green As Integer
    8.     Blue As Integer
    9.     Alpha As Integer
    10. End Type
    11.  
    12. Private Type GRADIENT_RECT
    13.     UpperLeft As Long
    14.     LowerRight As Long
    15. End Type
    16.  
    17. Const GRADIENT_FILL_RECT_H As Long = &H0
    18. Const GRADIENT_FILL_RECT_V  As Long = &H1
    19. Const GRADIENT_FILL_TRIANGLE As Long = &H2
    20. Const GRADIENT_FILL_OP_FLAG As Long = &HFF
    21.  
    22. Private Declare Function GradientFillRect Lib "msimg32" Alias "GradientFill" (ByVal hdc As Long, pVertex As TRIVERTEX, ByVal dwNumVertex As Long, pMesh As GRADIENT_RECT, ByVal dwNumMesh As Long, ByVal dwMode As Long) As Long
    23.  
    24. Private Function LongToUShort(Unsigned As Long) As Integer
    25. LongToUShort = CInt(Unsigned - &H10000)
    26. End Function
    27.  
    28. Private Sub Form_Load()
    29. Me.ScaleMode = vbPixels
    30. End Sub
    31.  
    32. Private Sub Form_Paint()
    33.     Dim vert(1) As TRIVERTEX
    34.     Dim gRect As GRADIENT_RECT
    35.  
    36.     With vert(0)
    37.         .x = 0
    38.         .y = 0
    39.         .Red = 0&
    40.         .Green = 0&
    41.         .Blue = 0&
    42.         .Alpha = 0&
    43.     End With
    44.  
    45.     With vert(1)
    46.         .x = Me.ScaleWidth
    47.         .y = Me.ScaleHeight
    48.         .Red = 0&
    49.         .Green = 0&
    50.         .Blue = LongToUShort(&HFF00&)
    51.         .Alpha = 0&
    52.     End With
    53.  
    54.     gRect.UpperLeft = 0
    55.     gRect.LowerRight = 1
    56.  
    57.     GradientFillRect Me.hdc, vert(0), 2, gRect, 1, GRADIENT_FILL_RECT_H
    58. End Sub

    Cheers

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