CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Coloring thumbs on CScrollBar

  1. #1
    Join Date
    Jan 2009
    Posts
    342

    Coloring thumbs on CScrollBar

    I am trying to coloring thumbs on CScrollBar control ... in order to achieve that, I derived a class from CScrollBar, named CScrollbarExt, and I handled CtlColor:
    Code:
    protected:
    	//{{AFX_MSG(CScrollBarExt)
    	afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
    	//}}AFX_MSG
    and
    Code:
    HBRUSH CScrollBarExt::CtlColor(CDC* pDC, UINT nCtlColor) 
    {
    	// TODO: Change any attributes of the DC here
    
    	// TODO: Return a non-NULL brush if the parent's handler should not be called
    	return m_Brush;
    	return NULL;
    }
    of course, m_Brush has a custom color, and scrollbar shaft has custom color ... but how can I draw thumbs of this CScrollBar object ? What can I do for that ?
    I attach a little sample project to illustrate the issue ...
    Attached Files Attached Files

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

    Re: Coloring thumbs on CScrollBar

    I guess you should use custom draw to achieve this.
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2009
    Posts
    342

    Re: Coloring thumbs on CScrollBar

    I have tried to handle ON_WM_DRAWITEM():
    Code:
    void CScrollBarExt::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
    	// TODO: Add your message handler code here and/or call default
    
    //	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
    
    	CScrollBar::OnDrawItem(nIDCtl, lpDrawItemStruct);
    }
    and I put a breakpoint here, but the code didn't pass by here ...
    Overriding OnPaint I guess it is not a proper solution ...
    Last edited by mesajflaviu; December 9th, 2015 at 02:13 AM.

  4. #4
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Coloring thumbs on CScrollBar

    It's my understanding that the CScrollBar control supports neither the owner-draw (WM_DRAWITEM) nor the custom-draw (NM_CUSTOMDRAW) specifications.

    If the control does not support owner-draw, then you will never receive the WM_DRAWITEM message.

  5. #5
    Join Date
    Jan 2009
    Posts
    342

    Re: Coloring thumbs on CScrollBar

    Kindly thank you Mike ... and how should I get/set thumbs color of CScrollbar ? As I said before, I don't think that redrawing whole control could be a solution ...

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

    Re: Coloring thumbs on CScrollBar

    Quote Originally Posted by mesajflaviu View Post
    and how should I get/set thumbs color of CScrollbar ?
    I believe, you just couldn't, as Win32 API does not provide any way for this, as far as I know.

    As I said before, I don't think that redrawing whole control could be a solution ...
    Then you should find/buy some thirdpaty scroll bar control implementing what you wish.
    Best regards,
    Igor

  7. #7
    Join Date
    Jan 2009
    Posts
    342

    Re: Coloring thumbs on CScrollBar

    OK, thank you ... at least I know where to go.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)