Introduction
Implementing
Rulers
inside of
Splitter
Panes - 2.
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
Collapse
Copy
Code
#include "Ruler.h"
class CChildFrame : public CMDIChildWnd
{
...
private: CRulerSplitterWnd m_Rulers; public: void ShowRulers(BOOL bShow); void UpdateRulersInfo(stRULER_INFO stRulerInfo); ...
};
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;
}
void CChildFrame::ShowRulers(BOOL bShow)
{
m_Rulers.ShowRulers(bShow);
}
void CChildFrame::UpdateRulersInfo(stRULER_INFO stRulerInfo)
{
m_Rulers.UpdateRulersInfo(stRulerInfo);
}
SDI
way
Collapse
Copy
Code
#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.
Collapse
Copy
Code
void CDemoView::OnMouseMove(UINT nFlags, CPoint point)
{
UpdateRulersInfo(RW_POSITION, GetScrollPosition(), point);
...
void CDemoView::OnVScroll(UINT nSBCode, UINT nPos,
CScrollBar* pScrollBar)
{
UpdateRulersInfo(RW_VSCROLL, GetScrollPosition());
...
void CDemoView::OnHScroll(UINT nSBCode,
UINT nPos, CScrollBar* pScrollBar)
{
UpdateRulersInfo(RW_HSCROLL, GetScrollPosition());
and finally
Collapse
Copy
Code
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*)GetParentFrame())->UpdateRulersInfo(pRulerInfo);
((CChildFrame*)GetParentFrame())->UpdateRulersInfo(pRulerInfo);
}