On Jan 24, 2:34 am, "ou" <o...@ab.auone-net.jp> wrote:
Env: WindowsXP, VC++6.00
If I create a SDI or MDI based on CScrollView by AppWizard and build/run it,
A blank view withoutscrollbars is showed .
I wonder if it is possible to show both thescrollbars, althought they are
in disabled status?
TIA
ou
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
//
#include "stdafx.h"
#include "StringTime.h"
#include "StringTimeDoc.h"
#include "StringTimeView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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 arbitraryscrollbars
}
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
#ifdef _DEBUG
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;}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CStringTimeView message handlers
void CStringTimeView::OnInitialUpdate()
{
//CSize sizeTotal;
//sizeTotal.cx=800;
//sizeTotal.cy=4000;
// AddingScrollBars
//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);
}
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
ClientRect and it is to small.
CRect rect; // Load the page size desired into this CRect structure.