Click here to Skip to main content
11,935,012 members (49,623 online)
Click here to Skip to main content
Add your own
alternative version


52 bookmarked

Implementing Rulers inside of Splitter Panes - 2

, 18 Dec 2002 CPOL
Rate this:
Please Sign up or sign in to vote.
Using fixed panes to add rulers to your view

Sample Image - Mdi.gif


Implementing Rulers inside of Splitter Panes - 2, is based on Stefan Ungureanu's work. This article provides an example to implementation in an MDI and SDI application.

I have changed the way to create the ruler, add function to Show/Hide the ruler and reformat some part of code.


MDI way

#include "Ruler.h"
class CChildFrame : public CMDIChildWnd
    private: CRulerSplitterWnd m_Rulers; //Ruler object
    public: void ShowRulers(BOOL bShow);//Toggle the ruler
    void UpdateRulersInfo(stRULER_INFO stRulerInfo);//Update the ruler
//Create the ruler

BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, 
                                CCreateContext* pContext)
    if (!m_Rulers.CreateRulers(this, pContext)) {
        TRACE("Error creation of rulers\n");
        return CMDIChildWnd::OnCreateClient(lpcs, pContext);
    return TRUE;

//Toggle the ruler
void CChildFrame::ShowRulers(BOOL bShow)


//Update the ruler

void CChildFrame::UpdateRulersInfo(stRULER_INFO stRulerInfo)

SDI way

#include "Ruler.h"
class CMainFrame : public CFrameWnd

All the rest is the same as MDI implementation.


In your view (In this case CScrollView), catch >OnMouseMove, OnVScroll and OnHScroll messages to interact with the ruler.

//Update mouse position on the ruler

void CDemoView::OnMouseMove(UINT nFlags, CPoint point)
    UpdateRulersInfo(RW_POSITION, GetScrollPosition(), point);
    //Update vertical scroll range and position of the ruler
    void CDemoView::OnVScroll(UINT nSBCode, UINT nPos, 
                                    CScrollBar* pScrollBar)
        UpdateRulersInfo(RW_VSCROLL, GetScrollPosition());
        //Update horizontal scroll range and position of the ruler
        void CDemoView::OnHScroll(UINT nSBCode, 
                    UINT nPos, CScrollBar* pScrollBar)
            UpdateRulersInfo(RW_HSCROLL, GetScrollPosition());

and finally

void CDemoView::UpdateRulersInfo(int nMessage, CPoint ScrollPos, CPoint Pos)
    stRULER_INFO pRulerInfo;
    pRulerInfo.uMessage = nMessage;
    pRulerInfo.ScrollPos = ScrollPos;
    pRulerInfo.Pos = Pos;
    pRulerInfo.DocSize = m_ImageSize;
    pRulerInfo.fZoomFactor = m_fZoomFactor;
    //CMainFrame in SDI
    //CChildFrame in MDI

Any way, take a look in the demo!

That's it!



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


About the Author

Systems / Hardware Administrator DCUtility
Canada Canada

You may also be interested in...

Comments and Discussions

GeneralOh, the code finally appeals! Pin
xxxyyyzzz22-Dec-02 21:42
memberxxxyyyzzz22-Dec-02 21:42 
GeneralRe: Oh, the code finally appeals! Pin
feier6-Aug-03 19:05
sussfeier6-Aug-03 19:05 
GeneralGood GUI, Low Speed Pin
xuell0019-Dec-02 18:05
memberxuell0019-Dec-02 18:05 

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
Web03 | 2.8.151126.1 | Last Updated 19 Dec 2002
Article Copyright 2002 by DCUtility
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid