Implementing Rulers inside of Splitter Panes

Environment: -->


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
class CMainFrame : public CFrameWnd

The next step is to create the splitter itself and the views. The code below matches a SDI application that accomodates 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
IMPLEMENT_FX_RULER_SPLITTER(<className>, <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
GetDocument()->UpdateAllViews(this, 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.

Download source - 5 KB

Date Last Updated: February 3, 1999


  • Thank you very much!!!

    Posted by Legacy on 01/15/2004 12:00am

    Originally posted by: kpld

    Thanks a lot!!!!!!!

  • Here

    Posted by Legacy on 09/03/2003 12:00am

    Originally posted by: Tom Tom

  • Help with source code

    Posted by Legacy on 09/02/2003 12:00am

    Originally posted by: Ivan

    I'm trying to implement a ruler such as shown in your article. But I'm having trouble integrating your codes into my application. Can you e-mail me the whole source code used for implementing the ruler application so that I can see what went wrong with my integration?

    Thanks in advance.

  • what is m_wndBar?

    Posted by Legacy on 07/10/2003 12:00am

    Originally posted by: propeller

    I have read your code, but I don't know what is of m_wndBar,
    would you like to explain for me?
    Thank you a lot.

  • Need more source code

    Posted by Legacy on 07/09/2003 12:00am

    Originally posted by: Klaus H.

    Your implementation seems to be exactly what I need, but unfortunately I can't get my application built after integrating your code (many undefined items/functions). So I'd be deeply grateful if you could provide me the source code of your application as a whole, to see how I have to amend my
    application so that it works together with your implementation.

    Many thanks in advance
    and best regards

  • Tom Tom, Thank you very much....!!!(^▽^)//

    Posted by Legacy on 03/14/2003 12:00am

    Originally posted by: Niccole Mai

    The material is excellent!!!I indebted to you for I made program easily... Thank very much.

  • a reference web site

    Posted by Legacy on 03/02/2003 12:00am

    Originally posted by: TomTom

    You had better to see the below site:

  • Would you show me your .exe file & program source code?...

    Posted by Legacy on 02/28/2003 12:00am

    Originally posted by: Niccole Mai

    I will insert "ruler" at my program...
    So, My programming standard is low...<(^ ^; )
    If you show me, I will thank to you.

  • How about a demo source?

    Posted by Legacy on 12/19/2002 12:00am

    Originally posted by: Huynh Ba Thuy

    Dear Stefan Ungureanu,
    Your article is excellent but I can't follow your steps in this paper.I don't understand it. Could you give me a demo source sothat I can complite and run it?
    Thank you very much.
    Yours sincerely.

  • Help me!

    Posted by Legacy on 09/17/2002 12:00am

    Originally posted by: lbwtusm

    I cann't use the code in my programe , somebody help me!
    I'll thanks a lot !
    Best Regards!

  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

  • Live Event Date: December 18, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this upcoming webcast …

Most Popular Programming Stories

More for Developers

RSS Feeds