Results 1 to 8 of 8

Thread: [RESOLVED] How to draw gradient over toolbar?

  1. #1

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Resolved [RESOLVED] How to draw gradient over toolbar?

    Am trying to emulate the gradient look in explorer so am using the code below (i found here on vbforums) to draw gradient over the toolbar in vb6sp6, using the toolbar in common controls v5sp2, but nothings happens.

    I enabled theme by using manifest in my app.



    vb Code:
    1. Private Type TRIVERTEX
    2.     x As Long
    3.     y As Long
    4.     Red As Integer 'Ushort value
    5.     Green As Integer 'Ushort value
    6.     Blue As Integer 'ushort value
    7.     Alpha As Integer 'ushort
    8. End Type
    9. Private Type GRADIENT_RECT
    10.     UpperLeft As Long  'In reality this is a UNSIGNED Long
    11.     LowerRight As Long 'In reality this is a UNSIGNED Long
    12. End Type
    13.  
    14. Const GRADIENT_FILL_RECT_H As Long = &H0 'In this mode, two endpoints describe a rectangle. The rectangle is
    15. 'defined to have a constant color (specified by the TRIVERTEX structure) for the left and right edges. GDI interpolates
    16. 'the color from the top to bottom edge and fills the interior.
    17. Const GRADIENT_FILL_RECT_V  As Long = &H1 'In this mode, two endpoints describe a rectangle. The rectangle
    18. ' is defined to have a constant color (specified by the TRIVERTEX structure) for the top and bottom edges. GDI interpolates
    19. ' the color from the top to bottom edge and fills the interior.
    20. Const GRADIENT_FILL_TRIANGLE As Long = &H2 'In this mode, an array of TRIVERTEX structures is passed to GDI
    21. 'along with a list of array indexes that describe separate triangles. GDI performs linear interpolation between triangle vertices
    22. 'and fills the interior. Drawing is done directly in 24- and 32-bpp modes. Dithering is performed in 16-, 8.4-, and 1-bpp mode.
    23. Const GRADIENT_FILL_OP_FLAG As Long = &HFF
    24.  
    25. 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
    26. Private Function LongToUShort(Unsigned As Long) As Integer
    27.     'A small function to convert from long to unsigned short
    28.     LongToUShort = CInt(Unsigned - &H10000)
    29. End Function
    30. Private Sub Form_Load()
    31.     'KPD-Team 1999
    32.     'URL: [url]http://www.allapi.net/[/url]
    33.     'E-Mail: [email][email protected][/email]
    34.     'API uses pixels
    35.     Me.ScaleMode = vbPixels
    36. End Sub
    37. Private Sub Form_Paint()
    38.     Dim vert(1) As TRIVERTEX
    39.     Dim gRect As GRADIENT_RECT
    40.  
    41.     'from black
    42.     With vert(0)
    43.         .x = 0
    44.         .y = 0
    45.         .Red = 0&
    46.         .Green = 0& '&HFF&   '0&
    47.         .Blue = 0&
    48.         .Alpha = 0&
    49.     End With
    50.  
    51.     'to blue
    52.     With vert(1)
    53.         .x = Me.ScaleWidth
    54.         .y = Me.ScaleHeight
    55.         .Red = 0&
    56.         .Green = 0&
    57.         .Blue = LongToUShort(&HFF00&)
    58.         .Alpha = 0&
    59.     End With
    60.  
    61.     gRect.UpperLeft = 0
    62.     gRect.LowerRight = 1
    63.  
    64.  GradientFillRect GetDC(tbMain.hwnd), vert(0), 2, gRect, 1, GRADIENT_FILL_RECT_H
    65. End Sub


    Does anybody knows why the code is not working?
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to draw gradient over toolbar?

    tbMain.hwnd is not what you want. You want the child window of the tbMain.hwnd.

    Read the posts in this thread, it applies.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: How to draw gradient over toolbar?

    thanks Lavolpe, this solves my problem
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  4. #4

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: [RESOLVED] How to draw gradient over toolbar?

    Please one more thing, if i want to translate this structure

    vb Code:
    1. With vert(0)
    2.         .x = 0
    3.         .y = 0
    4.         .Red = 0&
    5.         .Green = 0& '&HFF&   '0&
    6.         .Blue = 0&
    7.         .Alpha = 0&
    8.     End With

    from color values like #eeead6 to the individual red,green, and blue, how do i get these values in ushort
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  5. #5
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: [RESOLVED] How to draw gradient over toolbar?

    (Not in answer to your last question) but just in case it could be useful for you, i have a thread in the CodeBank about chaging Toolbar background to any color or using a picture as pattern, here is the link:
    http://www.vbforums.com/showthread.php?t=381167

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] How to draw gradient over toolbar?

    Quote Originally Posted by coolcurrent4u View Post
    ...
    from color values like #eeead6 to the individual red,green, and blue, how do i get these values in ushort
    What is #eeead6? Looks like an html color value? If it is then
    Code:
    Red = CLng("&H" & Mid$("#eeead6",2,2))
    Green = CLng("&H" & Mid$("#eeead6",4,2))
    Blue= CLng("&H" & Right$("#eeead6",2))
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: [RESOLVED] How to draw gradient over toolbar?

    Quote Originally Posted by jcis View Post
    (Not in answer to your last question) but just in case it could be useful for you, i have a thread in the CodeBank about chaging Toolbar background to any color or using a picture as pattern, here is the link:
    http://www.vbforums.com/showthread.php?t=381167
    Thanks for replying, but if you notice, i am trying to solve the question i asked in that thread in this thread
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  8. #8

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: [RESOLVED] How to draw gradient over toolbar?

    Quote Originally Posted by LaVolpe View Post
    What is #eeead6? Looks like an html color value? If it is then
    Code:
    Red = CLng("&H" & Mid$("#eeead6",2,2))
    Green = CLng("&H" & Mid$("#eeead6",4,2))
    Blue= CLng("&H" & Right$("#eeead6",2))
    thanks laVolpe. if i have any issues with it, i'll let you know
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

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