pallagommosa
pallagommosa

Reputation: 558

Skinning MFC scrollbar

Premise: I need to change the colors of the default CScrollBar defined in MFC (thumb + track + arrows), but after doing some research I realized that this isn't exactly an easy task.

Question: would it be better if I tried to draw OVER the existing scrollbar, or should I create a new scrollbar control from scratch?

I've already looked at this link: https://www.codeproject.com/Articles/14724/Replace-a-Window-s-Internal-Scrollbar-with-a-custo but the proposed method does not seem to work for newer versions of Windows (from Vista onwards).

Any advice is appreciated, thanks in advance.

Upvotes: 2

Views: 733

Answers (1)

Nick
Nick

Reputation: 471

We had exactly the same problem and your attempt to overdraw the original scrollbar was what we tried first. We dropped that attempt again due to some issues, which I don't remember in detail (not receiving all mouse or draw messages, flickering, ...). Our solution was some effort, but works now:

We implemented first a class CCustomScrollBar, which is NOT derived from CScrollBar, because the CScrollBar is just a wrapper around the Windows implementation and overwriting OnPaint() doesn't work perfect. And yes, all things must be implemented from scratch.

Second we implemented a template class CWndCustomScrollBar keeping two CCustomScrollBars and managing all around them as a standard window would do with its embedded scrollbars. The free client area then can be achieved via a method GetClientRectWithoutScrollBar() to work similar as a standard window would do.

Upvotes: 1

Related Questions