Click here to Skip to main content
Click here to Skip to main content

Add XP Style Scrollbar to listctrl, listbox and so on (by self-draw)

By , 8 Mar 2005
 
Sample Image - self-draw_XPScrollbar.jpg

Introduction

One of my recent projects needed to beautify UI, but when the app does not run on WinXP, the intrinsic scrollbar of common controls is too ugly. So I use self-draw CScrollWnd instead.

At present, only VSCROLL is supported. HSCROLL will be added when I have time to do it, and any help will be appreciated (you can add it by yourself).

Trick

The biggest problem to implement a scrollbar is to locate thumb properly. To solve this problem, I have used many ways, but at the end, a very convenient and reliable method was found: step by step approach.

Code

void CScrollWnd::MoveThumb(CPoint ptOffset)

{ if(!IsMouseInRange(WM_VSCROLL))
  return;
 CPoint ptCursor;
 GetCursorPos(&ptCursor);
 ScreenToClient(&ptCursor); 

 CPoint ptCurPos = ptCursor;
 int nMaxTimes=200;

 int nTimes = 0;
 int nStep = 1;//accuracy

 CPoint ptNewPos = ptOffset + GetRect(HT_THUMB).CenterPoint();
 while(abs(ptNewPos.y - ptCurPos.y)>nStep && nTimes++<nMaxTimes)
 {
  BOOL bDirDown = ptCurPos.y>ptNewPos.y;
  NotifyBuddy(WM_VSCROLL,MAKEWPARAM(bDirDown?SB_LINEDOWN:SB_LINEUP,0));
  
  UpdateScrollBar();
  ptNewPos = ptOffset + GetRect(HT_THUMB).CenterPoint();
 }
}

See the attached source code for more details.

Sorry for my poor English. My mother tongue is Chinese. :)

History

  • 8th March, 2005: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

xwp
Software Developer www.MayGion.com
China China
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5 Pinmemberdlsyaim6 Nov '11 - 16:58 
GeneralCombbox Pinmemberlroels20 Aug '07 - 20:48 
Generalsocksv5 specification, details Pinmemberavinu28 Jul '07 - 21:56 
GeneralError in Zip File PinmemberSrirama Kalyan7 May '07 - 4:46 
GeneralError in ZIP file PinmemberConradB5 Oct '06 - 19:38 
GeneralGood Pinmembervcfans23 Mar '06 - 15:02 
GeneralCan't unzip the zip file Pinmemberchinni_uday1 Mar '06 - 20:10 
GeneralFailed to add HScroll PinmemberSandeep A.C15 Feb '06 - 0:15 
GeneralUnable to Unzip PinmemberK.Senthil Babu14 Jul '05 - 20:59 
Generalcant download PinmemberSam Chris5 May '05 - 2:58 
GeneralRedraw bug on Win2000 PinmemberKochise8 Mar '05 - 21:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 8 Mar 2005
Article Copyright 2005 by xwp
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid