Results 1 to 21 of 21

Thread: [RESOLVED] Background color of a Scrollbar?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    84

    Resolved [RESOLVED] Background color of a Scrollbar?

    What system color is the background color of a Scrollbar? On an application there are many scrollbars (grids, textboxes. lists. etc). And one lonely hand crafted custom control. (let's call it myVScroll). I have made the buttons, and thumb of myVScroll look like the 'real thing'. But depending on what the individual PC settings are, the shaft (is that what it is?) of the native scrollbars are slightly different colors. To maximize the eye candy, I need the shaft color of myVScroll (myVScroll.Backcolor) to be the same color as the native scrollbars shaft color. What is that color?

    TIA, Bob.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Background color of a Scrollbar?

    Have you tested vbWindowBackground yet?

  3. #3
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: Background color of a Scrollbar?

    Bob

    Hopefully dilettante's offering does the trick.
    But, for curiosity purposes on my part, could you post a screen-shot of
    • what you have
    • what you want (once you get there)


    Spoo

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    84

    Re: Background color of a Scrollbar?

    OK, here is where it is today. Using the standard Win10 theme ...

    Attachment 152111

    This is with myVScroll backcolor set to &HF0F0F0. This seems to be a close match to the generic MSHFlexgrid horizontal scrollbar. Thanks for the pointer dilettante, but in this case (and on this PC), vbWindowBackground is too white.

    Now, set the app to run in Reduced color mode, I see this

    Name:  Noname.bmp
Views: 4271
Size:  35.4 KB

    Close, but not first prize. If I edit the bottom right corner of the picture, I see this

    Name:  Noname.bmp
Views: 4253
Size:  35.4 KB

    Notice the texture of the horizontal scrollbar. How do they do that?
    Bob.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    84

    Re: Background color of a Scrollbar?

    Oops, where did attachment 152111 go? Here it is again

    Name:  Noname.bmp
Views: 4253
Size:  38.2 KB

  6. #6
    Lively Member
    Join Date
    Sep 2016
    Location
    Texas panhandle
    Posts
    64

    Re: Background color of a Scrollbar?

    It is not a 'system color'. It is a PatternBrush.
    See this link:
    http://www.planet-source-code.com/vb...63046&lngWId=1

  7. #7
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: Background color of a Scrollbar?

    Bob

    OK, thanks

    Given the "lost" attachment issue, just to be sure ..
    • what you have .. post #5
    • working to get .. post #4


    Right?

    Spoo

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    84

    Re: Background color of a Scrollbar?

    This picture shows what remains to be done. This is the bottom right corner of an MSHFlexgrid set to show 'classic' scrollbars. Again, MyVScrollbar is the vertical one. You can clearly see the solid color of the body of MyVScrollbar vs the 'brushed' body of the Microsoft horizontal scrollbar.

    Name:  Noname.bmp
Views: 4376
Size:  191.8 KB

    The 'patternbrush' tip from VBClassic04 is the breakthrough I needed. Some heavy duty code in this project (for a lightweight like me). In fact, I might just use the whole thing and trash MyVScrollbar if I can get the 'themed' mode to work. For me all it shows is the classic look, nothing like Win10 scrollbar to be seen (yes, I'm running it as test.exe and the manifest is in the same folder).

    Anyone see a Win10 theme?
    Bob.

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

    Re: Background color of a Scrollbar?

    External manifests on Win7 and above do not typically work. You should consider embedding the manifest into your compiled exe. Here is a link to a project of mine. You do not need to use the project to embed a manifest, but in that link (post #3) describes how to manually embed manifests into a VB resource file which gets compiled into your exe.

    Manifests do not automatically theme user-created custom controls. If you are creating your own control, you need to apply themes yourself via code, using the theme APIs. Manifests theme Windows controls (window classes).

    To see if your manifest is being used/applied, simply add a typical intrinsic control (button, textbox, checkbox, etc) on your form and recompile. If properly manifested, the control should be themed.
    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}

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Background color of a Scrollbar?

    Hmmm, that intrinsic VScrollBar is a tricky booger. I thought I'd play around with sub-classing it and see what I could get accomplished. It has the standard WM_PAINT and WM_ERASEBKGND messages as would be expected.

    However, if you try to repaint it (FillRect with CreateSolidBrush) on WM_ERASEBKGND, nothing much happens.

    If you try to repaint it on WM_PAINT, that re-paints it, however...
    If you just exit the callback function (not letting the chain continue), it gets caught in a loop whereby it just keeps calling WM_PAINT.
    If you let the chain continue, our re-paint gets over-written.

    Apparently, further downstream, there's something that tells the VScrollBar to keep calling WM_PAINT until it gets painted the way it wants.
    That makes some sense since there's the up-button, down-button, scroll-button, as well as the actual exposed scroll background. And that doesn't even cover the 3D effects on those buttons.

    Therefore, if sticking with the intrinsic VScrollBar, I'm somewhat stumped on how to alter its colors with sub-classing.

    Best Regards,
    Elroy

    EDIT1: Also, I checked to see if that thing has children, and it doesn't.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Background color of a Scrollbar?

    Ahh, I was looking at a VB6 Scrollbar control.

    Here is a VScroll at the left and an MSHFlexGrid on the right. Windows 10-1703, Common Controls 6 (UxTheme) manifest:

    Name:  sshot.png
Views: 4329
Size:  1.1 KB

  12. #12
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Background color of a Scrollbar?

    For me, it'd be nice if we just had total control over the VScrollBar and HScrollBar, with both defaulting to the way the VB6 intrinsic controls look (or possibly themed).

    But I'm not thinking that's going to happen without a complete roll-your-own approach.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    84

    Re: Background color of a Scrollbar?

    Another small step for mankind, a giant step for me. Without checking the release date of the test project from VBClassic04, it is before Win 7. Some tweaking of the project, and 'themes' came to life (and thanks to LaVolpe) no manifest necessary.

    Now, before I can flag this thread as resolved, I would like some assistance with a more robust fix than my simple hack to get themes to work.

    Here's my analysis of why the project doesn't automatically theme (pseudo code below).

    Code:
    Private Sub pvOnPaint(ByVal lhDC As Long)
    
    Case m_eStyle = [sClassic] Or (m_eStyle = [sThemed] And m_bIsLuna = False)
            ' paint classic scrollbar
    
    Case m_eStyle = [sFlat]
           ' paint flat scrollbar
    
    Case m_eStyle = [sThemed]
           ' paint themed scrollbar
    Because m_bIsLuna is always False for Win 10, when Themed mode is selected, The Classic case statement code is executed. m_bIsLua is set True/False in the pvCheckEnvironment sub. his is the code that needs some serious work. I don't understand the significance m_bIsLuna at all, any/all assistance is appreciated.

    Thanks, Bob.

  14. #14
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Background color of a Scrollbar?

    I played with GetThemeSysColor() to retrieve a few related colors. Supposedly requesting the brush just gives a brush of the same color, no patterning.

    In any case, just a VScroll and ListBox, not even any manifest, on Win10 I see:

    Name:  sshot.png
Views: 4566
Size:  2.8 KB

    Examining a screenshot, ButtonFace and ThreeDFace are identical and match the ListBox scrollbar color. So no telling which might be correct, or if some other iColorID is the correct one for scrollbars.

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    84

    Re: Background color of a Scrollbar?

    Resolved, with thanks to all. I hacked away at the code for an hour or two, then found a newer version at http://www.vbforums.com/showthread.p...on-Design-mode that had all the fixes (and more) that I needed. Again, thanks. Bob.

  16. #16
    Lively Member
    Join Date
    Sep 2016
    Location
    Texas panhandle
    Posts
    64

    Re: [RESOLVED] Background color of a Scrollbar?

    Elroy:
    Hmmm, that intrinsic VScrollBar is a tricky booger. I thought I'd play around with sub-classing it and see what I could get accomplished. It has the standard WM_PAINT and WM_ERASEBKGND messages as would be expected.
    The msg of interest here is WM_CTLCOLORSCROLLBAR
    The code below paints the scrollbar correctly with no code in the WinProc


    Code:
    Option Explicit
    'reference: SSubTimer6.dll
    Implements ISubclass
    Private Const WM_CTLCOLORSCROLLBAR = &H137
    
    Private Sub Form_Load()
     AttachMessage Me, hwnd, WM_CTLCOLORSCROLLBAR
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
     DetachMessage Me, hwnd, WM_CTLCOLORSCROLLBAR
    End Sub
    
    Private Property Let ISubclass_MsgResponse(ByVal RHS As SSubTimer6.EMsgResponse)
    '
    End Property
    
    Private Property Get ISubclass_MsgResponse() As SSubTimer6.EMsgResponse
    '
    End Property
    
    Private Function ISubclass_WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    '
    End Function

  17. #17
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: [RESOLVED] Background color of a Scrollbar?

    VBC

    Could you possibly post a screenshot to illustrate that?

    Spoo

  18. #18
    Lively Member
    Join Date
    Sep 2016
    Location
    Texas panhandle
    Posts
    64

    Re: [RESOLVED] Background color of a Scrollbar?

    Name:  SB.JPG
Views: 4366
Size:  26.5 KB

  19. #19
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: [RESOLVED] Background color of a Scrollbar?

    Nice ..

  20. #20
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [RESOLVED] Background color of a Scrollbar?

    Preventing the Form from seeing WM_CTLCOLORSCROLLBAR does work... but only correctly when you have a CC6 manifest.


    Name:  sshot IDE.png
Views: 4213
Size:  2.9 KB
    IDE Run (no manifest)


    Name:  sshot EXE.png
Views: 4219
Size:  2.8 KB
    EXE Run (with CC6 manifest)


    The attached demo is self-contained. No need for any 3rd party DLLs.
    Attached Files Attached Files

  21. #21
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: [RESOLVED] Background color of a Scrollbar?

    This is such an old problem (with the same fix subclassing WM_CTLCOLORSCROLLBAR) it should probably be in the FAQ

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