Click here to Skip to main content
15,880,427 members
Articles / Desktop Programming / MFC
Article

Implementing Rulers inside of Splitter Panes - 2

Rate me:
Please Sign up or sign in to vote.
4.59/5 (15 votes)
18 Dec 2002CPOL 108.7K   3.4K   54   13
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)


Written By
CEO
Canada Canada

Comments and Discussions

 
BugCRulerSplitterWnd::CreateRulers bug Pin
ralfsch25-Nov-13 20:15
ralfsch25-Nov-13 20:15 
Generaluse GetSysColorBrush instead of CreateSolidBrush [modified] Pin
RedFraggle13-Jun-09 9:22
RedFraggle13-Jun-09 9:22 
QuestionHow to use it in diffent map mode??? Pin
wp51_cn11-Feb-07 2:15
wp51_cn11-Feb-07 2:15 
GeneralGreat work! Pin
kellyonlyone12-Mar-06 23:42
sponsorkellyonlyone12-Mar-06 23:42 
QuestionCan I add to a dialog? Pin
St.Devil8-Oct-05 17:01
St.Devil8-Oct-05 17:01 
GeneralTotally Wrong Idea Pin
Martial Spirit31-Jan-05 18:16
Martial Spirit31-Jan-05 18:16 
GeneralRe: Totally Wrong Idea Pin
smjones24-Mar-05 13:04
smjones24-Mar-05 13:04 
QuestionCan I add the rulers &quot;inside&quot; a splitter window? Pin
Nathan Yong25-Jan-05 16:08
Nathan Yong25-Jan-05 16:08 
Generalbug: changing zoom doesn't refresh ruler windows Pin
Keith Bussell13-Jan-05 12:32
Keith Bussell13-Jan-05 12:32 
GeneralI tried to use your classes but something's wrong Pin
islobell8-May-04 0:22
islobell8-May-04 0:22 
GeneralOh, the code finally appeals! Pin
TeleStar22-Dec-02 20:42
TeleStar22-Dec-02 20:42 
GeneralRe: Oh, the code finally appeals! Pin
feier6-Aug-03 18:05
feier6-Aug-03 18:05 
GeneralGood GUI, Low Speed Pin
xuell0019-Dec-02 17:05
xuell0019-Dec-02 17: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.