passed to SetScrollSizes.
On Tuesday, February 05, 2008 2:03 AM Charlie Chan wrote:
On Jan 24, 2:34 am, "ou" <o...@ab.auone-net.jp> wrote:
Here is a somewhat working example. It loads the text from a text
file into the main window. The scrollbars are there when the main
window loads. However, when the scrollbars moves the text is not
updated. The only active scrollbar is the vertical one. If you
stretch the window the text reloads properly. I have not been able to
get the text to update properly when the vertical scrollbar is moved.
// StringTimeView.cpp : implementation of the CStringTimeView class
//
static char THIS_FILE[] = __FILE__;
/////////////////////////////////////////////////////////////////////////////
// CStringTimeView
IMPLEMENT_DYNCREATE(CStringTimeView, CScrollView)
BEGIN_MESSAGE_MAP(CStringTimeView, CScrollView)
//{{AFX_MSG_MAP(CStringTimeView)
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStringTimeView construction/destruction
CStringTimeView::CStringTimeView()
{
SetScrollSizes(MM_TEXT, CSize(0,0));// Set arbitrary scroll bars
}
CStringTimeView::~CStringTimeView()
{
}
BOOL CStringTimeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CStringTimeView drawing
void CStringTimeView::OnDraw(CDC* pDC)
{
CStringTimeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// int DrawText( const CString& str, LPRECT lpRect,
// UINT nFormat )
CRect rect;
GetClientRect(&rect);
pDC->DrawText(pDoc->GetString(),&rect,DT_LEFT);
}
/////////////////////////////////////////////////////////////////////////////
// CStringTimeView printing
BOOL CStringTimeView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CStringTimeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /
*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CStringTimeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /
*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CStringTimeView diagnostics
void CStringTimeView::AssertValid() const
{
CScrollView::AssertValid();
}
void CStringTimeView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CStringTimeDoc* CStringTimeView::GetDocument() // non-debug version is
inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CStringTimeDoc)));
return (CStringTimeDoc*)m_pDocument;
}
/////////////////////////////////////////////////////////////////////////////
// CStringTimeView message handlers
void CStringTimeView::OnInitialUpdate()
{
//CSize sizeTotal;
//sizeTotal.cx=800;
//sizeTotal.cy=4000;
// Adding Scroll Bars
//SetScrollSizes(MM_TEXT, sizeTotal);
ResetScrollSizes();
CScrollView::OnInitialUpdate();
}
void CStringTimeView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*
pScrollBar)
{
CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CStringTimeView::ResetScrollSizes()
{
CClientDC aDC(this);
OnPrepareDC(&aDC);
CSize DocSize = GetDocument()->GetDocSize();
aDC.LPtoDP(&DocSize);
SetScrollSizes(MM_TEXT, DocSize);
//OnUpdate(NULL,1,NULL);
}
void CStringTimeView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CScrollView::OnPrepareDC(pDC, pInfo);
}
On Tuesday, February 05, 2008 2:03 AM Charlie Chan wrote:
scottmcp> wrote:
e
is
ps
I must admit I do not know how to find the logical size of a text file
to achieve this. I have done a lot of searching but have got no results.
On Sunday, February 24, 2008 11:00 PM Charlie Chan wrote:
On Jan 27, 7:33 pm, Charlie Chan <charlie_c...@suddenlink.net> wrote:
======================
I solved my scollbar problem. I have been struggling under a
misconception about the ClientRect. It returns the client rect
coordinates of (left/top) and (right/bottom). Here is what I was
doing wrong:
void CStringTimeView::OnDraw(CDC* pDC)
{
CStringTimeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// int DrawText( const CString& str, LPRECT lpRect, UINT nFormat )
CRect rect;
GetClientRect(&rect);
// This loads the text into a rectangle no bigger than the
ClientRect and it is to small.
pDC->DrawText(pDoc->GetString( ),&rect,DT_LEFT);
}
Here is how it should read:
CStringTimeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// int DrawText( const CString& str, LPRECT lpRect,
// UINT nFormat )
CRect rect; // Load the page size desired into this CRect structure.
rect.left=0;
rect.right=1150;
rect.top=0;
rect.bottom=1150;
// This loads the text into a predetermined CRect struction
that is big enough to hold the
// entire page of text that was loaded into a CString
pDC->DrawText(pDoc->GetString( ),&rect,DT_LEFT);
}
I have been working on this so long that I'm exhausted and have the
flu but satisfaction is sweet success.