15,976
社区成员
发帖
与我相关
我的任务
分享BOOL
CSmartEditorView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
CWnd *pParentWnd = CWnd::FromHandlePermanent( cs.hwndParent );
if( NULL == pParentWnd ||
!pParentWnd->IsKindOf( RUNTIME_CLASS( CSplitterWnd ) ) )
{
// View must always create its own scrollbars,
// if only it's not used within splitter
cs.style |= ( WS_HSCROLL | WS_VSCROLL );
}
cs.lpszClass = AfxRegisterWndClass( CS_DBLCLKS );
return CView::PreCreateWindow(cs);
}
void CSmartEditorView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
SCROLLINFO si;
int page_lines, line_count, new_topline;
CView::OnVScroll(nSBCode, nPos, pScrollBar);
// Note we cannot use nPos because of its 16-bit nature
memset( &si, 0, sizeof( SCROLLINFO ) );
si.cbSize = sizeof( SCROLLINFO );
si.fMask = SIF_ALL;
VERIFY( GetScrollInfo( SB_VERT, &si ) );
page_lines = GetScreenLines();
line_count = GetLineCount();
switch( nSBCode )
{
case SB_TOP:
new_topline = 0;
break;
case SB_BOTTOM:
new_topline = line_count - page_lines + 1;
break;
case SB_LINEUP:
new_topline = m_top_line - 1;
break;
case SB_LINEDOWN:
new_topline = m_top_line + 1;
break;
case SB_PAGEUP:
new_topline = m_top_line - si.nPage + 1;
break;
case SB_PAGEDOWN:
new_topline = m_top_line + si.nPage - 1;
break;
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
new_topline = si.nTrackPos;
break;
default:
return;
}
if( new_topline < 0 )
{
new_topline = 0;
}
if( new_topline >= line_count )
{
new_topline = line_count - 1;
}
BOOL bUpdateSiblings = FALSE;
if( m_top_line != new_topline )
{
int scroll_line_count = m_top_line - new_topline;
m_top_line = new_topline;
ScrollWindow( 0, scroll_line_count * GetLineHeight() );
UpdateWindow();
}
RecalcVScrollBar( TRUE );
}
void
CSmartEditorView::RecalcVScrollBar( BOOL bPositionOnly )
{
SCROLLINFO si;
memset( &si, 0, sizeof( SCROLLINFO ) );
si.cbSize = sizeof( SCROLLINFO );
if( bPositionOnly )
{
//只更新区域,应该是用户纯滚动屏幕
si.fMask = SIF_POS;
si.nPos = m_top_line;
}
else
{
if( GetScreenLines() >= GetLineCount() && m_top_line > 0)
{
m_top_line = 0;
Invalidate();
}
si.fMask = SIF_DISABLENOSCROLL | SIF_PAGE | SIF_POS | SIF_RANGE;
si.nMin = 0;
si.nMax = GetLineCount() - 1;
si.nPage = GetScreenLines();
si.nPos = m_top_line;
}
VERIFY( SetScrollInfo( SB_VERT, &si ) );
}void CMyView::Create(CWnd *pParentWnd, const RECT &rect, UINT nID, DWORD dwStyle)
{
CView::Create(NULL, "", dwStyle, rect, pParentWnd, nID);
m_HScrollBar.Create( SBS_HORZ | SBS_TOPALIGN, CRect( rect.left, rect.bottom, rect.right - rect.left, 20), pParentWnd, 0 );
m_HScrollBar.ShowScrollBar();
}