Click here to Skip to main content
11,928,078 members (50,392 online)
Click here to Skip to main content
Add your own
alternative version


36 bookmarked

Implementing Rulers inside of Splitter Panes

, 4 Jan 2000
Rate this:
Please Sign up or sign in to vote.
Using fixed panes to add rulers to your view

Sample Image - rulers.jpg


Many applications that display images or documents show rulers on both sides of the view to indicate your position within the page and allow a more accurate positioning of the cursor. Implementing rulers can be difficult, since we must reserve a space for them inside the view (this gets more difficult on a CScrollView-derived class). Another solution is to use "fixed" splitters (meaning they cannot be resized). The example below demonstrates how to build such rulers.

The code

The code implementing the ruler splitter window and views used for the rulers themselves can be found in ruler.h and ruler.cpp. Below is a sample of how to use them.

Inside the frame window (which can be either a CFrameWnd or CMDIChildWnd-derived class):

// class definition
 CMainFrame : public

The next step is to create the splitter itself and the views. The code below matches a SDI application that accommodates the code above inside a splitter pane, but you can easily adjust it to fit your needs. In the OnCreateClient member of the CMainFrame class, add code to create the splitter inside the right pane:

// class definition

  <parentSplitter>, 0, 1, pContext->m_pNewViewClass);

What you have to do next is send notifications to the rulers to let them know about the scroll position change or zoom change. The rulers can also display the mouse position as the cursor moves; this is done also by sending notifications to the rulers with just a few lines of code like:

// class definition

  VW_VSCROLL, (CObject*)(GetScrollPosition().y));

Available hint types are (hint parameters are passed as INTs using a cast to CObject*):

VW_HSCROLL View is scrolled horizontally
VW_VSCROLL View is scrolled vertically
VW_HPOSITION Cursor position changed on the x axis
VW_VPOSITION Cursor position changed on the y axis

The code is quite easy to follow and change to meet your needs, but if you need assistance, contact me. Also please send me bugs or updates, to keep this solution up-to-date. For more details on the sample application, contact me.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Romania Romania
... coming in a short while

You may also be interested in...

Comments and Discussions

QuestionpDoc Null in consequence of OnMouseActivate Pin
Member 568844321-Jan-15 6:25
memberMember 568844321-Jan-15 6:25 
Generaluse GetSysColorBrush instead of CreateSolidBrush Pin
RedFraggle13-Jun-09 10:41
memberRedFraggle13-Jun-09 10:41 
Questionimplementation ? Pin
Ken Keray16-Sep-03 8:35
memberKen Keray16-Sep-03 8:35 
AnswerRe: implementation ? Pin
NoSpam!16-Feb-04 9:19
memberNoSpam!16-Feb-04 9:19 
GeneralRe: implementation ? Pin
Ken Keray17-Feb-04 12:31
memberKen Keray17-Feb-04 12:31 
Questionhow does it work in MM_A mode Pin
JQEang25-May-03 20:46
memberJQEang25-May-03 20:46 
GeneralOh, the code finally appeals! Pin
xxxyyyzzz22-Dec-02 21:38
memberxxxyyyzzz22-Dec-02 21:38 
QuestionGetting this Damm thing to work? Pin
Jimbo4030-Nov-00 0:39
memberJimbo4030-Nov-00 0:39 
AnswerRe: Getting this Damm thing to work? Pin
harris7-Jul-01 11:54
memberharris7-Jul-01 11:54 
GeneralNeeds Better Docs and a sample Pin
anonymous13-Apr-00 5:57
sussanonymous13-Apr-00 5:57 
GeneralRe: Needs Better Docs and a sample Pin
Jason K.M. Wong17-Sep-00 17:42
sussJason K.M. Wong17-Sep-00 17:42 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 5 Jan 2000
Article Copyright 2000 by _stefanu_
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid