Implementing Rulers inside of Splitter Panes | CodeGuru

Implementing Rulers inside of Splitter Panes

Environment: –> Introduction 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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 2, 1999
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: –>

Introduction

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
{
[…]
protected:
	DECLARE_FX_RULER(CMainFrame)

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.