Click here to Skip to main content
Licence CPOL
First Posted 18 Dec 2002
Views 80,447
Bookmarked 49 times

Implementing Rulers inside of Splitter Panes - 2

By | 18 Dec 2002 | Article
Using fixed panes to add rulers to your view

Sample Image - Mdi.gif

Introduction

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.

Implementation

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<BR>
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)
{
    m_Rulers.ShowRulers(bShow);<BR>
}

//Update the ruler<BR>
void CChildFrame::UpdateRulersInfo(stRULER_INFO stRulerInfo)
{
    m_Rulers.UpdateRulersInfo(stRulerInfo);
}

SDI way

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

All the rest is the same as MDI implementation.

Interaction

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

//Update mouse position on the ruler<BR>
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
    ((CMainFrame*)GetParentFrame())->UpdateRulersInfo(pRulerInfo);
    //CChildFrame in MDI
    ((CChildFrame*)GetParentFrame())->UpdateRulersInfo(pRulerInfo);
}

Any way, take a look in the demo!

That's it!

Enjoy!

License

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

About the Author

DCUtility

Other
DCUtility
Canada Canada

Member

Home Page

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. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generaluse GetSysColorBrush instead of CreateSolidBrush [modified] PinmemberRedFraggle9:22 13 Jun '09  
QuestionHow to use it in diffent map mode??? Pinmemberwp51_cn2:15 11 Feb '07  
GeneralGreat work! Pinmemberkellyonlyone23:42 12 Mar '06  
QuestionCan I add to a dialog? PinmemberSt.Devil17:01 8 Oct '05  
GeneralTotally Wrong Idea PinmemberMartial Spirit18:16 31 Jan '05  
GeneralRe: Totally Wrong Idea Pinmembersmjones13:04 24 Mar '05  
I did a search on Code Project for any articles that Martial Spirit has written. You know, it came up empty. Hmmm.
 
Manufacturing Software Developer
Hewlett-Packard Company
QuestionCan I add the rulers "inside" a splitter window? PinmemberNathan Yong16:08 25 Jan '05  
Generalbug: changing zoom doesn't refresh ruler windows PinmemberKeith Bussell12:32 13 Jan '05  
GeneralI tried to use your classes but something's wrong Pinmemberislobell0:22 8 May '04  
GeneralOh, the code finally appeals! Pinmemberxxxyyyzzz20:42 22 Dec '02  
GeneralRe: Oh, the code finally appeals! Pinsussfeier18:05 6 Aug '03  
GeneralGood GUI, Low Speed Pinmemberxuell0017:05 19 Dec '02  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120528.1 | Last Updated 19 Dec 2002
Article Copyright 2002 by DCUtility
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid