Forum
Please
Log In
to post a new message or reply to an existing one. If you are not registered, please
register.
NOTE: Some forums may be read-only if you are not currently subscribed to
our technical support services.
Subject |
Author |
Date |
|
tera t
|
Jan 17, 2008 - 7:50 PM
|
Hello.
In Drawvw.cpp, will CExtScrollBar be utilized? Or will standard CSrollBar be utilized? When I click scroll bar, a bar shines for an instant. Do you do any special thing?
|
|
Technical Support
|
Jan 19, 2008 - 12:21 PM
|
Please follow these steps for improving the source code of your scrollable view window:
1) The scrollbar creation code should be: m_wndScrollBarH.m_eSO = CExtScrollBar::__ESO_BOTTOM;
m_wndScrollBarV.m_eSO = CExtScrollBar::__ESO_RIGHT;
if( ! m_wndScrollBarV.Create(
WS_CHILD|WS_VISIBLE|SBS_VERT|SBS_RIGHTALIGN,
CRect(0,0,0,0),
this,
1
)
)
{
ASSERT( FALSE );
return -1;
}
if( ! m_wndScrollBarH.Create(
WS_CHILD|WS_VISIBLE|SBS_HORZ|SBS_BOTTOMALIGN,
CRect(0,0,0,0),
this,
2
)
)
{
ASSERT( FALSE );
return -1;
}
m_wndScrollBarH.SyncReservedSpace( &m_wndScrollBarV );
m_wndScrollBarV.SyncReservedSpace( &m_wndScrollBarH );
RepositionBars( 0, 0xFFFF, 0 ); 2) The OnSize() , OnHScroll() and OnVScroll() handler methods should finally invoke the following: RepositionBars( 0, 0xFFFF, 0 );
3) A bit better implementation of the CWnd::GetScrollBarCtrl() virtual method (though your current version is OK): CScrollBar * CSkeViewPPW::GetScrollBarCtrl( int nBar ) const
{
ASSERT_VALID( this );
if( m_hWnd == NULL || (! ::IsWindow(m_hWnd) ) )
return NULL;
if( nBar == SB_HORZ )
{
if( m_wndScrollBarH.GetSafeHwnd() != NULL )
return ( const_cast < CExtScrollBar * > ( &m_wndScrollBarH ) );
}
else if( nBar == SB_VERT )
{
if( m_wndScrollBarV.GetSafeHwnd() != NULL )
return ( const_cast < CExtScrollBar * > ( &m_wndScrollBarV ) );
}
return NULL;
} 4) The CView::OnScroll() and CView::OnScrollBy() virtual methods should be overridden in your view window. BOOL CSkeViewPPW::OnScroll( UINT nScrollCode, UINT nPos, BOOL bDoScroll /*= TRUE*/ )
{
ASSERT_VALID( this );
bDoScroll;
BOOL bRetVal = CScrollView::OnScroll( nScrollCode, nPos, FALSE );
Invalidate();
return bRetVal;
}
BOOL CSkeViewPPW::OnScrollBy( CSize sizeScroll, BOOL bDoScroll /*= TRUE*/ )
{
ASSERT_VALID( this );
bDoScroll;
INT xOrig, x, yOrig, y, xMax = GetScrollLimit( SB_HORZ ), yMax = GetScrollLimit( SB_VERT );
xOrig = x = GetScrollPos(SB_HORZ);
yOrig = y = GetScrollPos(SB_VERT);
DWORD dwStyle = GetStyle();
CScrollBar * pBarH = GetScrollBarCtrl( SB_HORZ ), * pBarV = GetScrollBarCtrl( SB_VERT );
if( ( pBarH != NULL && (!pBarH->IsWindowEnabled()) )
|| ( pBarH == NULL && (dwStyle&WS_HSCROLL) != 0 )
)
sizeScroll.cx = 0;
if( ( pBarV != NULL && (!pBarV->IsWindowEnabled()) )
|| ( pBarV == NULL && (dwStyle&WS_VSCROLL) != 0 )
)
sizeScroll.cy = 0;
x += sizeScroll.cx;
if( x < 0 )
x = 0;
else if( x > xMax )
x = xMax;
y += sizeScroll.cy;
if( y < 0 )
y = 0;
else if( y > yMax )
y = yMax;
if( x == xOrig && y == yOrig )
return FALSE;
if( x != xOrig )
SetScrollPos( SB_HORZ, x );
if( y != yOrig )
SetScrollPos( SB_VERT, y );
Invalidate();
return TRUE;
}
|
|
tera t
|
Jan 18, 2008 - 5:22 PM
|
Hello.
I programed it as follows. However, the scroll bar is displayed, but does not work.
class MT_EXPORT CSkeViewPPW : public CExtPPVW < CScrollView > { ...........................................
}
CScrollBar * CSkeViewPPW::GetScrollBarCtrl( int nBar ) const { ASSERT_VALID( this ); if( m_hWnd == NULL || (! ::IsWindow(m_hWnd) ) ) return NULL; ASSERT( nBar == SB_HORZ || nBar == SB_VERT ); if( nBar == SB_HORZ ) { if( m_wndScrollBarH.GetSafeHwnd() != NULL ) return ( const_cast < CExtScrollBar * > ( &m_wndScrollBarH ) ); } // if( nBar == SB_HORZ ) else { if( m_wndScrollBarV.GetSafeHwnd() != NULL ) return ( const_cast < CExtScrollBar * > ( &m_wndScrollBarV ) ); } // else from if( nBar == SB_HORZ ) return NULL; }
void CSkeViewPPW::OnInitialUpdate() { m_wndScrollBarH.m_eSO = CExtScrollBar::__ESO_BOTTOM; m_wndScrollBarV.m_eSO = CExtScrollBar::__ESO_RIGHT; if( ! m_wndScrollBarV.Create( WS_CHILD|WS_VISIBLE|SBS_VERT|SBS_RIGHTALIGN, CRect(0,0,0,0), this, 1 ) ) { ASSERT( FALSE ); return; } if( ! m_wndScrollBarH.Create( WS_CHILD|WS_VISIBLE|SBS_HORZ|SBS_BOTTOMALIGN, CRect(0,0,0,0), this, 2 ) ) { ASSERT( FALSE ); return; } m_wndScrollBarH.SyncReservedSpace( &m_wndScrollBarV ); m_wndScrollBarV.SyncReservedSpace( &m_wndScrollBarH );
CSize sizeTotal(1,1); CSize Page(100,50); CSize Line(10,10); SetScrollSizes(MM_TEXT, sizeTotal /*,Page,Line*/ );
}
void CSkeViewPPW::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { pScrollBar = GetScrollBarCtrl( SB_HORZ ); CExtPPVW < CScrollView >::OnHScroll(nSBCode, nPos, pScrollBar);
Invalidate(); UpdateWindow(); }
void CSkeViewPPW::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { pScrollBar = GetScrollBarCtrl( SB_VERT ); CExtPPVW < CScrollView >::OnVScroll(nSBCode, nPos, pScrollBar);
Invalidate(); UpdateWindow(); }
Thank you
|
|
Technical Support
|
Jan 18, 2008 - 11:06 AM
|
The view window in this sample application is based on the CExtSplitterWnd splitter window which uses CExtScrollBar scroll bars controls instead of MFC’s CScrollBar . You can use a CExtScrollBar control independently of any Prof-UIS classes. This is simply a repainted version of CScrollBar which also supports themed animations.
|
|