CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Join Date
    Jan 2009
    Posts
    399

    Customize control scrollbar

    I get a task: to color the control scrollbar (a gridctrl scrollbar, whatever). In the first attempting I didn't succeded ... So, I started to trying coloring a CListBox scrollbar ... I developed a derived CListBox where I override OnCtlColor:
    Code:
    HBRUSH CMyListBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    	HBRUSH hbr = CListBox::OnCtlColor(pDC, pWnd, nCtlColor);
    
    	// TODO: Change any attributes of the DC here
    
    	// TODO: Return a different brush if the default is not desired
    
    	if(CTLCOLOR_STATIC == nCtlColor)
    	{
    		pDC->SetTextColor(RGB(200, 34, 0));
    		pDC->SetBkColor(RGB(250, 230, 200));
    		return m_Brush;
    	}
    
    	return hbr;
    }
    not working ...
    I override CTestDlg::OnCtlColor:
    Code:
    HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    
    	// TODO: Change any attributes of the DC here
    
    	// TODO: Return a different brush if the default is not desired
    
    //	if(CTLCOLOR_SCROLLBAR == nCtlColor)
    	{
    		pDC->SetTextColor(RGB(200, 34, 0));
    		pDC->SetBkColor(RGB(250, 230, 200));
    		return m_Brush;
    	}
    
    	return hbr;
    }
    I colored everything, except scrollbars ) ... I attached the app demo ...

    I already tried this solution:

    http://www.codeproject.com/Articles/...r-with-a-custo

    but in my case, didn't worked ...

    My question is, how can I color the control scrollbar ? It is possible ? If yes, how ?
    I'll appreciate any hint, link, etc.

    Thank you.
    Attached Files Attached Files

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Customize control scrollbar

    Quote Originally Posted by mesajflaviu View Post
    I already tried this solution:

    http://www.codeproject.com/Articles/...r-with-a-custo

    but in my case, didn't worked ...
    Define "didn't work".
    And how does "your" case differ from the case described in the article?
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2009
    Posts
    399

    Re: Customize control scrollbar

    Soon as I applied that solution, the control scrollbar doesn't drawn anymore, part of the control (CGridCtrl) didn't drawn as well, the focus on this control (CGridCtrl) has weird behavior ... and I have to mention that this solution applied on test application that has the same CGridCtrl, work pretty correct (looks ugly, but is working) ...

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Customize control scrollbar

    Perhaps, you add some things to _your_ control that are incompatible with the technique used in this article?
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Customize control scrollbar

    There are two kinds of scrollbars:
    1. scrollbars which are shown in windows having WS_HSCROLL and/or WS_VSCROLL style;
    2. scrollbar common controls (of window class "ScrollBar").


    WM_CTLCOLOR messages are sent to the parent to allow changing the default colors of its child controls. So, what you tried to achieve in your test application uploaded here, works only for scrollbar controls (kind #2).
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Jan 2009
    Posts
    399

    Re: Customize control scrollbar

    In fact, it is logical to be like that, as long CTLCOLOR_BTN change color of a button, CTLCOLOR_EDIT change color of a edit box, CTLCOLOR_SCROLLBAR should change color of an CScrollbar control, not some scrollbars of some controls ... I have to dig in ...

  7. #7
    Join Date
    Jan 2009
    Posts
    399

    Re: Customize control scrollbar

    Quote Originally Posted by VictorN View Post
    Perhaps, you add some things to _your_ control that are incompatible with the technique used in this article?
    On the first sight, there is nothing incompatible by that solution ...

  8. #8
    Join Date
    Jan 2009
    Posts
    399

    Re: Customize control scrollbar

    I think I found a solution to colorize the scrollbars: using FlatSB_SetScrollProp ... and is almost done, except one thing: OS redraw the control scrollbars when I click on scrollbars ... could you give a hand to solve this issue ? I am struggling for weeks about this problem ... see attachment ...
    Attached Files Attached Files

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Customize control scrollbar

    Quote Originally Posted by mesajflaviu View Post
    I think I found a solution to colorize the scrollbars: using FlatSB_SetScrollProp ... and is almost done, except one thing: OS redraw the control scrollbars when I click on scrollbars ... could you give a hand to solve this issue ? I am struggling for weeks about this problem ... see attachment ...
    Super!
    You did not answer this question yet:
    Quote Originally Posted by VictorN View Post
    Define "didn't work".
    And how does "your" case differ from the case described in the article?
    So you are expecting that we will be now searching for the differences between the original code and your own implementation?
    Victor Nijegorodov

  10. #10
    Join Date
    Jan 2009
    Posts
    399

    Re: Customize control scrollbar

    I think I make myself unclear: I succeeded into color scrollbars (of an control, let say CListBox), but not with this: http://www.codeproject.com/Articles/...r-with-a-custo solution, but using FlatSB_SetScrollProp ... The only thing that remain is that this scrollbars (custom colorized) are switch back into original color when I click them ... yes, seems to be the same project, but it has another solution to colorize scrollbars ...
    Last edited by mesajflaviu; February 26th, 2015 at 04:36 AM.

  11. #11
    Join Date
    Jan 2009
    Posts
    399

    Re: Customize control scrollbar

    "And how does "your" case differ from the case described in the article?"

    That solution applied on my case, is not function at all, I mean, the scrollbars has vanish completely ... I know, sounds illogical, but this is the fact ... that is why I searched for another solution ...

    Yes, put this solution:
    http://www.codeproject.com/Articles/...r-with-a-custo
    into simple test app, had worked, but looks pretty ugly ... but when I had applied that on my real app, the scrollbars has disappeared completely ... so, the better choice is to search another solution ...
    Last edited by mesajflaviu; February 27th, 2015 at 07:06 AM.

  12. #12
    Join Date
    Jan 2009
    Posts
    399

    Re: Customize control scrollbar

    "So you are expecting that we will be now searching for the differences between the original code and your own implementation"

    I would not have this expectation, of course ... the only thing is, I didn't explain why scrollbars, once I applied FlatSB_SetScrollProp properties, is redrawn as original color ... that is all ...

  13. #13
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Customize control scrollbar

    Quote Originally Posted by mesajflaviu View Post
    I think I found a solution to colorize the scrollbars: using FlatSB_SetScrollProp ... and is almost done, except one thing: OS redraw the control scrollbars when I click on scrollbars ... could you give a hand to solve this issue ? I am struggling for weeks about this problem ... see attachment ...
    From MSDN:
    Remarks

    Note Flat scroll bar functions are implemented in Comctl32.dll versions 4.71 through 5.82. Comctl32.dll versions 6.00 and higher do not support flat scroll bars.
    Best regards,
    Igor

  14. #14
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Customize control scrollbar

    Quote Originally Posted by mesajflaviu View Post
    but when I had applied that on my real app, the scrollbars has disappear completely ...
    ... which means you applied that wrong way.

    so, the better choice is to search another solution ...
    A choice, don't know better or worse, would be to understand the suggested solution in details. Did you? Do you understand what the code does, and what for? Do you see how new supplementary windows appear? Do you see how those windows change original z-order, subclass original controls, route scroll messages? Unless you do, all the code would seem doing a kind of magic while it's just a pure technique.
    Best regards,
    Igor

  15. #15
    Join Date
    Jan 2009
    Posts
    399

    Re: Customize control scrollbar

    Quote Originally Posted by Igor Vartanov View Post
    From MSDN:
    Ahh, I didn't noticed that flat scrollbars are available only until 5.8.2 ... my mistake.

Page 1 of 2 12 LastLast

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

Featured