Click here to Skip to main content
Click here to Skip to main content

Implementing Rulers inside of Splitter Panes - 2

By , 18 Dec 2002
 

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

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generaluse GetSysColorBrush instead of CreateSolidBrush [modified]memberRedFraggle13 Jun '09 - 9:22 
in MSDN, i found this:
 
To paint with a system color brush, an application should use GetSysColorBrush(nIndex) instead of CreateSolidBrush(GetSysColor(nIndex)), because GetSysColorBrush returns a cached brush instead of allocating a new one.
 
there are two places, where CreateSolidBrush is called in ruler.cpp, just search for them
 
The reason i looked for this was, i got resource leaks somewhere somehow. After opening/closing a lot of windows, i got error messages telling me there are no more resources available. Above changes fixed this problem.
 
btw.: thank you for posting your code here Smile | :)
 
modified on Saturday, June 13, 2009 3:28 PM

QuestionHow to use it in diffent map mode???memberwp51_cn11 Feb '07 - 2:15 
I see your code. but i don't know how to use it in anthoer map mode.
GeneralGreat work!memberkellyonlyone12 Mar '06 - 23:42 
Nice job,thanks!
If this ruler can be contained within the scrollbars of the view,it will be more cool!
Kelly
 
--------------------------------------------------------------------------
For high quality flow/diagram MFC/C++ Visio Like visualization Source Code,download XD++ at:
http://www.ucancode.net
 

-- modified at 5:43 Monday 13th March, 2006
QuestionCan I add to a dialog?memberSt.Devil8 Oct '05 - 17:01 
If I show rules on a dialog what can I do ?
If I need to move the picture anywhere what can I do?
If I need to show x-coordinate and y-coordinate what can I do?
 

 

 


GeneralTotally Wrong IdeamemberMartial Spirit31 Jan '05 - 18:16 
You need to have a look at photoshop, whoes ruler are just painted in same view, that's why your action is so slowly!
 
just use you mouse left click on scrollbar's button, you can observe this obviously.Unsure | :~
 
Best Regards
GeneralRe: Totally Wrong Ideamembersmjones24 Mar '05 - 13:04 
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 &quot;inside&quot; a splitter window?memberNathan Yong25 Jan '05 - 16:08 
Hi.
 
Anyone knows how to add the rulers inside a splitter window?
 
My situation is:
1. SDI
2. view area split into pane 0,0 and pane 0,1
3. pane 0,0 used as form view
4. pane 0,1 used as CSrollView to display picture
5. i need to add the rulers in pane 0,1
 
Please help. Thanks.
 
Best Regards,
Nathan

Generalbug: changing zoom doesn't refresh ruler windowsmemberKeith Bussell13 Jan '05 - 12:32 
From the demo app, select zoom out. Notice that the rulers don't repaint in their new state.
 
The fix: in CRulerView::UpdateRulersInfo(), check if m_fZoomFactor changed. If so, call Invalidate().
 
void CRulerView::UpdateRulersInfo(stRULER_INFO stRulerInfo)
{
  bool requiresRefresh = false;
 
  if(m_fZoomFactor != stRulerInfo.fZoomFactor)
  {
    m_fZoomFactor = stRulerInfo.fZoomFactor;
    requiresRefresh = true;
  }
 
  m_DocSize = stRulerInfo.DocSize;
  m_scrollPos = stRulerInfo.ScrollPos;
 
  if (stRulerInfo.uMessage == RW_POSITION) {
    DrawCursorPos(stRulerInfo.Pos);
  }
  else if ((m_rulerType == RT_HORIZONTAL) && (stRulerInfo.uMessage == RW_HSCROLL) ||
    (m_rulerType == RT_VERTICAL) && (stRulerInfo.uMessage == RW_VSCROLL)) {
    CDC* pDC = GetDC();
    OnDraw(pDC);
    ReleaseDC(pDC);
  }
  else
    requiresRefresh = true;
 
  if(requiresRefresh)
    Invalidate();
}

 
    -keithb
GeneralI tried to use your classes but something's wrongmemberislobell8 May '04 - 0:22 
Can you send me an example with a MDI App with multiview splitter?
GeneralOh, the code finally appeals!memberxxxyyyzzz22 Dec '02 - 20:42 
After almost two years waiting, we are happy to find that someone complete the code finally.
However, it seems the speed is too slow.

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

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